System Design Architectures

Interactive technical blueprints, capacity estimates, database sharding strategies, and visual flowcharts for the top 30 system design interview questions.

Target Architectures
AI Agent Architecture Blueprint

Human-in-the-Loop (HITL) Pause & Resume Engine

Transactional checkpoint state engine that pauses autonomous agent execution before high-stakes actions (financial transactions, DB drops, external emails) and resumes upon human authorization.

1. System Requirements

Functional
  • Intercept privileged tool actions dynamically based on configurable risk policies (e.g., spend > $50, database write queries, bulk external notifications).
  • Serialize current execution frames into durable storage, terminate worker threads to release compute, and dispatch authorization requests (Slack/Email/Web).
  • Resume execution idempotently upon receiving signed approval tokens with optional parameter edits by the human reviewer.
Non-Functional / SLA
  • Zero compute resource consumption while a workflow is in a suspended/awaiting approval state.
  • Guaranteed at-most-once execution of privileged tools to prevent duplicate transactions during resume retries.
  • Immutable audit logging of human approver identity, reasoning, and context diff for compliance standards (SOC2, HIPAA).

2. Scale & Resource Estimates

Throughput: 10,000 active suspended/pending workflows simultaneously with sub-100ms resume latency upon decision receipt.

Storage & RAM: 15 KB compressed execution state per workflow. 50,000 monthly approval events = 750 MB PostgreSQL storage.

3. System API Endpoints

// 1. Intercepted Tool Suspends Execution
POST /v1/agent/action-request
Payload:
{
  "workflow_id": "wf-90124",
  "tool": "execute_database_migration",
  "params": { "migration_sql": "ALTER TABLE users ADD COLUMN phone VARCHAR(20);" },
  "risk_tier": "HIGH"
}

Response (202 Accepted):
{
  "status": "SUSPENDED",
  "approval_id": "appr_782b1c",
  "approval_url": "https://aiagent.org/approvals/appr_782b1c",
  "expires_at": "2026-10-14T22:00:00Z"
}

// 2. Human Reviewer Submits Decision
POST /v1/agent/approvals/appr_782b1c/decision
Payload:
{
  "decision": "APPROVED", // or "REJECTED" or "EDITED"
  "approver": "sre-lead@company.com",
  "reason": "Verified non-blocking schema migration in staging"
}

Response (200 OK):
{
  "status": "RESUMED",
  "workflow_status": "RUNNING"
}

4. Database Schema Design

CREATE TABLE hitl_checkpoints (
    checkpoint_id VARCHAR(64) PRIMARY KEY,
    workflow_id VARCHAR(64) NOT NULL,
    thread_id VARCHAR(64) NOT NULL,
    state_payload JSONB NOT NULL, -- Compressed memory, call stack, tool call context
    pending_tool VARCHAR(64) NOT NULL,
    tool_args JSONB NOT NULL,
    risk_level VARCHAR(16) NOT NULL, -- 'LOW', 'MEDIUM', 'HIGH', 'CRITICAL'
    status VARCHAR(32) DEFAULT 'PENDING', -- 'PENDING', 'APPROVED', 'REJECTED', 'EXPIRED'
    approver VARCHAR(128),
    approval_notes TEXT,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    decided_at TIMESTAMP WITH TIME ZONE
);

CREATE INDEX idx_hitl_pending ON hitl_checkpoints(status, created_at);

5. Interactive High-Level Architecture

graph TD Agent["LLM Agent Execution Loop"] --> PolicyCheck{"Risk Policy Engine"} PolicyCheck -->|Safe Action| ExecTool["Execute Tool Directly"] PolicyCheck -->|High Risk Action| SaveFrame["Persist State Frame to DB"] SaveFrame --> Release["Release Worker Compute"] SaveFrame --> Dispatch["Dispatch Alert: Slack / Email / Webhook"] Dispatch --> Human["Human Approver Reviews Context"] Human -->|Approve or Reject| DecisionAPI["POST /agent/approvals/decision"] DecisionAPI --> ResumeWorker["Resume Worker and Hydrate State"] ResumeWorker --> ExecTool ExecTool --> NextStep["Continue Autonomous Loop"]

6. Scalability Deep Dive & Bottlenecks

Synchronous blocking ('holding the line') while waiting for human input is an anti-pattern that crashes during deployments and wastes server memory. Enterprise HITL architectures externalize all call stacks into durable state machines (Temporal, LangGraph checkpointer, or AWS Step Functions). When execution hits an interrupt boundary, the worker writes the memory frame to PostgreSQL and exits cleanly. When an approval webhook arrives days later, any available worker pod loads the frame and continues seamlessly.

7. Production Scaling Strategies

Stateless Worker Pool: State is entirely decoupled from compute instances, allowing zero-downtime rolling deploys without terminating paused human reviews.

TTL Expiration & Auto-Revocation: Approvals automatically expire after 24 hours to prevent stale execution states from executing unexpectedly.

Diff Visualization Generation: The approval UI automatically synthesizes before-and-after state diffs (e.g. database schema change preview or email draft preview) enabling reviewers to authorize decisions in seconds.

8. Runnable Production Starter Code

Scaffold