Agent Application DevelopmentAccount
Knowledge catalogChoose core direction and segmented content
knowledge unit 53AdvancedSystem designAbout 20 minutes

Understand → Implement → Debug → Design

A controlled task chain from evidence to publication

Connect identity, knowledge permissions, structured tools, persistence tasks, and audit releases into a recoverable system.

System designRAG+SQLpersistenceOutbox

Knowledge content check2026-10-03 · Check the source of the original question2026-10-02

Which step do you want to learn from this knowledge point?

Select the starting point based on the current basis, or you can go deeper one by one. When you encounter an unfamiliar concept, go back to the core principles first; use the knowledge exercises to check your understanding when you are finished.

Understand first

New to this knowledge point

Complete the prerequisite concepts, read the principles and counterexamples, and then explain why in your own words.

Start with core principles →

Realize again

Prepare to write the principles into code

Understand implementation steps and boundaries, complete small tasks, and check results against acceptance requirements.

View the code example →

Will troubleshoot

Need to handle failures and changes in conditions

Follow the continuous questioning to locate the failure premise, and then compare the migration cases to explain how the plan should be adjusted.

Continue to delve deeper into the problem →

Able to choose

Need to design or review plans

Combine engineering deductions and senior self-evaluation standards to explain the applicable conditions, costs and alternatives of the plan.

Analyze engineering scenarios →
Knowledge unit directory

LEARN · PRACTICE · REFLECT

Knowledge learning and personal records

My notes and review ↗

First read along the principles, Q&A and migration cases. When you need to check your understanding, switch to reinforcement exercises or start personal recording.

Answers and personal notes

Each modified commit will be kept as an independent history. Your level of mastery is up to you to evaluate yourself against the standards.

Core concept · A controlled task chain from evidence to publication

Understand the core principles first

Preparatory concepts:Business state machine, Snapshots and versions, Idempotent submission

Enterprise tasks should be recorded separately for reading evidence, generating drafts and publishing results, and then connecting them with versions and authorizations. Durable orchestration restores control flow but does not automatically guarantee consistent evidence or that external writes occur only once.

Separate three kinds of facts

Retrieval records identify source versions, drafts record generated content, and publication receipts establish external acceptance. Mixing them in chat obscures proposal versus completion during recovery. Keep source lists, draft digests, approved proposals, and publication operation keys separately.

Define consistency explicitly

Appropriate database isolation can provide a read-consistent snapshot within one database. Files and databases usually lack a shared global transaction. State cutoff times or source versions, detect changes, and account for lag. Reads within one minute are not necessarily an atomic snapshot.

Approval does not close the effect window

Bind approval to the draft and recheck permissions and resource conditions before publication. An outbox atomically records local state and publication intent; delivery can repeat, requiring target deduplication or reconciliation. Stopping later steps cannot undo committed effects. This architecture is design guidance without enterprise production validation.

Check understanding with a question

Design an enterprise agent: check information, check database, generate reports and publish them with manual approval

Separate reading, generation, and publication. Trusted admission creates tenant-bound tasks; retrieval and SQL enforce access. Models produce versioned evidence-based drafts. State machines handle long work, while checkpoints remain distinct from effects. Record publication intent in an outbox, approve the specific draft, and dispatch with stable keys. Reconcile timeouts and validate isolation, recovery, and duplicates through audits and fault injection.

Realization and trade-offs

First determine the boundary and task status

The requirement is for internal enterprise reporting and does not require the model to be freely connected to all systems. The portal verifies identity and establishes tenant_id, run_id, task budget and version. The status can be queued, running, waiting_approval, publishing, succeeded, failed, canceled, and the conversion is verified by the backend. The conversation history is the user interaction data, and the task status is the basis for recovery; the database saves step input summaries, checkpoints and errors, and the document and draft contents are placed in permission-protected storage.

Obtain evidence using controlled tools

The retrieval service first limits the candidate range according to tenants and document permissions, then sorts them, and returns fragments, versions and sources. SQL tools give priority to exposing certain interfaces such as account balances and flow summaries; when dynamic queries are required, use read-only accounts, allowed tables, and query timeouts. Parsing and checking cannot replace database permissions. The model synthesizes reports of structured results with documented evidence, and the numerical calculations are left to the deterministic code. When no data is found, gaps are clearly pointed out and cannot be filled with similar accounts. The query parameters and snapshot time are attached to the reference, and sensitive parameters are appropriately redacted in the user output.

Design recovery and release separately

LangGraph's Persistence provides persistence mechanisms such as checkpoints, but saving the graph state does not mean that external operations only occur once. After the draft is generated, the persistent version is approved and bound to this version. The publishing intent is updated simultaneously within the database transaction and written to the outbox, which is delivered by the worker; this ensures that the local intent is submitted together with the queue record, and does not allow the remote service and the local database to be in the same transaction. Consumers may still make repeat purchases. When the peer supports idempotency keys, use a stable action_id and timeout the query results; when the peer does not support it, enter the pending verification state to avoid direct repeated sending.

Evaluate the architecture using failure scenarios

Temporal Activity Execution indicates that the activity may be executed multiple times, so business side effects must still be idempotent or explicitly limit retries. Whether to introduce a specialized workflow engine depends on the task duration, recovery requirements, and team operation and maintenance capabilities. You cannot add a system just to use popular frameworks. Set the total number of steps, token budget and deadline for each task. Stop new actions when cancelled. The final status of the remote request that has been sent needs to be checked. Five scenarios are used for acceptance: cross-tenant retrieval, worker crash after release, repeated message delivery, approval expiration, and model unavailability to check whether the public artifacts, task status, and audit records are consistent; these are design test goals.

code example

SQLite: local publish intent same transaction as outbox

Works on an empty SQLite database. The example only demonstrates local transaction writing and publishing intent, and does not implement permissions, approvals, consumers, peer idempotency, and recovery after version changes. You cannot claim end-to-end exactly-once based on this. Any statement failure must roll back the entire transaction by the caller; after the outbox insertion fails, the updated report status cannot be continued.

PRAGMA foreign_keys = ON;
CREATE TABLE report (
  tenant_id TEXT NOT NULL,
  report_id TEXT NOT NULL,
  version INTEGER NOT NULL,
  status TEXT NOT NULL CHECK (status IN ('draft', 'publishing', 'published')),
  PRIMARY KEY (tenant_id, report_id)
);
CREATE TABLE publish_outbox (
  tenant_id TEXT NOT NULL,
  action_id TEXT NOT NULL,
  report_id TEXT NOT NULL,
  report_version INTEGER NOT NULL,
  status TEXT NOT NULL DEFAULT 'pending',
  PRIMARY KEY (tenant_id, action_id),
  FOREIGN KEY (tenant_id, report_id) REFERENCES report(tenant_id, report_id)
);
INSERT INTO report VALUES ('tenant-a', 'report-1', 3, 'draft');
BEGIN TRANSACTION;
UPDATE report SET status = 'publishing'
WHERE tenant_id = 'tenant-a' AND report_id = 'report-1'
  AND version = 3 AND status = 'draft';
INSERT INTO publish_outbox (tenant_id, action_id, report_id, report_version)
SELECT 'tenant-a', 'action-1', report_id, version FROM report
WHERE tenant_id = 'tenant-a' AND report_id = 'report-1'
  AND changes() = 1;
COMMIT;
SELECT report_id, report_version, status FROM publish_outbox;

expected output

report-1|3|pending

Engineering deduction

scene
Hypothetical engineering scenario: The fund management department requires the report to cite both system documents and account flow, and release it after confirmation by the supervisor.
design decisions
The read interface enforces tenant permissions, the numbers are calculated by the determiner, and reports and release approvals are bound to versions.
Verify target
The goal is that each number can be played back, unapproved manuscripts cannot be published, and repeated messages do not generate additional business actions; it has not yet been verified as a real enterprise effect.
applicable boundary
The sample outbox only covers local transactions, and peer consistency relies on idempotent interfaces or result verification.

Continuous questions and answers

Continue reading along with the premises and constraints of the problem. Understand the reference answers first, then try to put away the answers and explain the cause and effect and trade-offs in your own words.

Draw inferences from one example: If the conditions change, how to deduce it?

First find out the conditions for change, and then determine which premises in the original plan still hold true. The following cases are teaching deductions to facilitate the transfer of principles to new problems.

Only generate internal drafts

Changing conditions:Remove external publishing and allow users to manually download and review.

Extended question:Which aspects can be simplified?

Derivation and reference solutions

It is not necessary to automatically publish outbox, but the read authorization, source list, draft version and download permissions must still be retained. The final state is defined as a draft saved and readable by authorized users; do not declare a successful build as an official release. Reducing the scope of the task does not mean that all evidence and isolation requirements disappear.

The principles that remain unchanged:The facts and authorization at each stage must still be clear and completed according to the definition of actual effects.

Automatically publish across days

Changing conditions:Sources and permissions may change, and external targets may be retried.

Extended question:How to maintain the meaning of the original approval?

Derivation and reference solutions

Persistent storage of approved objects and versions, checking the validity period, source impact and current authorization during execution, and re-proposing any changes. The original business key is retried and checked against the target; simply restoring the old checkpoint does not prove that the old action can still be executed.

The principles that remain unchanged:Restoring control flow cannot replace current business validity and effect verification.

Easy to make mistakes

  • Treat vector similarity filtering as permission isolation.
  • It is thought that saving the checkpoint will automatically ensure that the external writing is done once.
  • Treat external service timeouts as failures and retry unconditionally.

References

It is designed based on public technical information; the reference materials support the technical mechanism, and the scenarios and scoring standards are designed by this website and do not represent the original interview questions of a certain company. New Q&A and migration cases are added for principle explanation, and source verification and case operation verification are recorded separately.

Check how far you understand

After reading, you can explain the principles, boundaries, and trade-offs against these standards. It is up to you to evaluate your mastery; if further verification is needed, complete the small tasks below.

Basic standards met
It can separate search, query, generation and approval for release.
Intermediate and advanced signals
Clarify data permissions, definitions, persistence and tool receipts.
Senior Signal
Capacity, cost, fault recovery, canary release and end-to-end acceptance are given.

View verification records for independent examples

Hands-on verificationComplete on demand · Suggestions15 minutes

Draw boundaries and failure paths for the group treasurer's "query, analysis, report generation, approval and release".

Expand acceptance requirements and checkpoints
  • Amounts are derived from deterministic calculations
  • Separate read and publish authorizations
  • Failure has recoverable or pending status

Key inspections

  • Ability to describe how data permissions are passed along RAG, SQL and reporting artifacts.
  • Able to distinguish consistency between task state persistence and external side effects.
  • Ability to design clear states for limited budgets, failure recovery, and manual review.