KatInterview

Design a Reliable Poller for a Lagging Upstream Database

System DesignModel answer
MediumModel answerSystem Designpollingdata-pipelinesdistributed-systems

Last updated

Determine whether variable record lag allows a fixed polling interval to guarantee one new record per poll, then define a production-ready ingestion strategy.

Design a Reliable Poller for a Lagging Upstream Database

A upstream service emits one event every 30 seconds. You cannot inspect or modify this service. Each event eventually lands in database B — a read-only black box — with a per-record propagation delay anywhere from zero to five minutes. No event is ever dropped.

You control database C and a poller process that reads from B and writes into C. A downstream consumer reads from C and expects to process exactly one new record per request, never receiving duplicates or missing any record.

Before going live you are allowed an observation window in which you can watch real arrivals and calibrate your design. Once live, the business requirement is the shortest possible polling interval that still satisfies the one-record-per-request contract with zero failures.

Clarifying questions worth raising

  • Does B expose a stable cursor, offset, or sequence number you can query against?
  • Can B be queried for "give me at most one record I have not yet seen"?
  • Is it possible for events to appear in B out of the order they were generated?
  • Does a poll that returns zero results count as a contract failure?
  • Is C allowed to buffer multiple ingested records ahead of the one-at-a-time consumer?

Part 1 — Analyze the core requirement

Using worst-case reasoning, decide whether the known generation cadence (one per 30 s) and the known maximum lag (five minutes) are enough to choose a fixed polling interval that guarantees exactly one new arrival per poll.

Your answer should address:

  • A worst-case arrival argument, not an average-rate argument
  • The distinction between generation cadence and observed arrival cadence
  • Whether the guarantee as literally stated is achievable, and why or why not

Part 2 — Use the observation window

Describe what you would measure or prove during the boot/test phase before going live, and be honest about what a finite observation window can and cannot tell you.

Your answer should address:

  • How to establish stable record identity, arrival ordering, and a lag distribution
  • How to validate cursor semantics and idempotency
  • A warm-up or backlog-drain policy before the consumer starts
  • Why empirical observation is evidence, not proof, of a production bound

Part 3 — Define the live polling strategy

Propose a concrete design, including a polling rate, under clearly stated assumptions. The downstream consumer's one-at-a-time requirement must be preserved without pretending the source delivers exactly one record per interval.

Your answer should address:

  • How to decouple ingestion from one-at-a-time consumption
  • Durable cursors, deduplication, and retry behavior
  • Buffer sizing derived from the five-minute lag bound
  • Monitoring signals and the response plan if the lag bound is violated

Hints

Hint 1

Start with the worst case: two records generated 30 s apart could both propagate to B at the maximum five-minute lag and arrive at almost the same moment. A fixed interval calibrated to average behavior will fail in that scenario.

Hint 2

A buffer in C is the key architectural move. Separate the question 'how fast should I poll B?' from the question 'how does the consumer get exactly one record at a time?' — these do not have to be the same rate.

Hint 3

Think about what a cursor buys you: idempotent re-reads on retry, safe resume after a crash, and the ability to detect out-of-order arrivals. Commit the cursor to C only after successfully writing the record, not before.