KatInterview

Distributed Event Ledger, Pay Engine, Workflow Orchestration, and AI Query Assistant

System DesignModel answer
HardModel answerSystem Designevent-drivenworkflow-orchestrationLLM

Last updated

Design four backend systems: a deduplicated event counter, an immutable driver-pay ledger, a fault-tolerant offboarding workflow, and a permission-gated LLM expense assistant.

Background

Your platform serves a workforce-management product. Mobile and web clients emit usage events, field workers earn pay that must be settled exactly, employees leave and their access must be fully revoked, and managers want natural-language answers over expense records. You need to design four cooperating subsystems in a single interview session.

Constraints

  • Mobile SDKs may reconnect after hours offline and flush large backlogs. Events may arrive out of order, duplicated, or late — none can be silently dropped.
  • Real-time dashboards can tolerate stale data up to tens of minutes; monthly billing figures must be exact and auditable.
  • Offboarding touches seven to ten external services. Some steps can run in parallel, some have hard prerequisites, and some cannot be safely retried without a compensating action.
  • The expense assistant operates over two large datasets that span multiple tenants. Data boundaries must be enforced before any model call.

What to clarify before designing

  • For the event system: which fields uniquely identify a billing event, and which fields are mutable labels added after the fact?
  • For driver pay: when a rate is renegotiated, does it apply only to work completed from that point forward, or can it reopen unsettled past periods?
  • For offboarding: which external systems expose idempotency keys, support outbound webhooks, or offer a compensating "re-grant" action if a later step fails?

Part 1 — Counted and billed events

Design the full pipeline from SDK emission to dashboard widgets and to a monthly billing close.

Cover:

  • How events are accepted durably and deduplicated across retries and backlog flushes
  • How you handle event-time windowing when events arrive minutes or hours after the clock window they belong to
  • Why the approximate dashboard store and the exact billing ledger are separate systems, and how the billing ledger is reconciled at month-end

Part 2 — Field worker pay engine

Model the data layer that tracks completed work, applies effective-dated rate schedules, handles overlapping or duplicate job records, and exposes the difference between what has accrued and what has been paid out.

Cover:

  • How work records are kept immutable, and how rate changes are represented without mutating history
  • How the system detects and resolves time-span overlaps or duplicate job submissions
  • The shape of accrual, payment, and reconciliation APIs

Part 3 — Employee offboarding orchestrator

Design the service that drives a seven-to-ten step deprovisioning process: revoking credentials, closing active sessions, issuing a final pay run, archiving records, and notifying downstream systems.

Cover:

  • How the workflow state is persisted so that a crash mid-run can resume from exactly the right step
  • Per-step idempotency strategy and what compensation looks like when a late-stage step fails after an earlier one succeeded
  • How you minimize wall-clock completion time (parallelism), what triggers retry versus operator escalation, and how inbound webhooks from external systems are wired into the state machine

Part 4 — Natural-language expense assistant

A manager types a free-form question like "Show me all software subscriptions over $500 this quarter for the engineering team." Design the system that safely converts this into structured operations over employee records and expense records, returns correct aggregates, and streams the result back to the UI.

Cover:

  • How tenant scope and per-employee data permissions are enforced before the query reaches the model
  • How the model's output is turned into a typed, validated query plan rather than executed as raw text
  • When you use a deterministic tool call versus a multi-step agent loop
  • How streaming is handled without surfacing unvalidated partial results to the user

Hints

Hint 1

For Part 1, think about why you need two separate stores — one optimized for fast approximate reads and one for exact, auditable counts. An append-only ledger with a batch reconciliation job at billing close is a common pattern; ask yourself what the source of truth is when they diverge.

Hint 2

For Part 3, model the workflow as a DAG of steps with explicit states (pending, running, succeeded, failed, compensating). A durable execution engine (or a simple state table with a worker polling it) lets you resume after a crash without re-running completed steps. Draw the critical path first to find which steps block others.

Hint 3

For Part 4, the biggest trap is letting the LLM emit free-form code or queries that execute directly. Instead, constrain its output to a small vocabulary of typed operations (filter, group_by, sum, top_k) that your backend validates before running. Authorization happens on the resolved query plan, not on the raw natural-language string.