KatInterview

Sync Data from a Rate-Limited External API (3 req/s)

System DesignModel answer
MediumModel answerSystem Designrate-limitingdistributed-systemsdata-pipeline

Last updated

Design a distributed service that ingests and keeps data fresh from a third-party API capped at exactly 3 requests per second.

The Setup

Your company depends on data that lives inside a third-party service. You need to build a backend pipeline that continuously pulls that data into your own database and keeps it reasonably fresh. The provider's API enforces a strict ceiling of 3 requests per second. Any request that exceeds this cap is refused outright.

The core design challenge is making that constraint work across a fleet of workers that run in parallel, possibly on multiple machines.


What You Don't Know Yet — Ask First

Good candidates spend a few minutes clarifying scope before drawing boxes. Consider questions like:

  • Is the 3 req/s ceiling shared across your entire integration (one API key), or does each customer credential get its own independent allowance?
  • Is the window a strict rolling one-second interval or a fixed calendar second? Does the provider return a Retry-After header or equivalent when you breach it?
  • Are you doing a one-time historical backfill, ongoing periodic syncs, or near-real-time streaming? All three at once?
  • Does the provider offer bulk endpoints, large page sizes, filtering by modification timestamp, or push-based webhooks?
  • Who reads the data after you store it, and what is the cost to them when it arrives late?

State your assumptions explicitly if the interviewer leaves these open.


Part 1 — The Ingestion Pipeline

Design the end-to-end components: what decides what to fetch, what makes the actual HTTP calls, how results are stored, and how downstream systems learn about new data.

Cover:

  • The major components (scheduler, work queue, fetch workers, storage layer) and how they connect
  • The data model for tracking sync state — what does a "job" or "checkpoint" record look like?
  • The difference between a full backfill and an incremental sync, and when each applies
  • How you make writes idempotent so re-fetching the same page twice does not corrupt data
  • How consumers discover newly arrived or updated records

Part 2 — Enforcing the Global Rate Cap

Multiple workers running concurrently will happily blow past 3 req/s unless something coordinates them. A per-process counter is not enough — it cannot see the other processes.

Address:

  • What mechanism enforces a single, shared limit across all workers and hosts?
  • How does a worker "ask permission" before firing a request, and what does it do while it waits?
  • How do you account for the provider's measurement window (rolling vs. fixed) and build in a small safety margin?
  • When a request is rejected (HTTP 429), how do you handle the retry — backoff curve, jitter, and whether retries count against the same budget?
  • What happens if the coordination layer (e.g., the rate-limiter store) becomes unavailable?

Part 3 — When Work Outpaces the Budget

At 3 req/s you get at most 10,800 requests per hour. If the data volume or freshness requirements demand more than that, something has to give.

Cover:

  • The arithmetic: how do you calculate whether your budget is sufficient given data volume and target freshness SLA?
  • Techniques to extract more value from each request (larger pages, delta queries, batch endpoints, conditional GET with ETags)
  • How you prioritize work so a large historical backfill does not block time-sensitive incremental updates
  • What fairness looks like when you pull data for multiple tenants that share one API key
  • How you surface backlog depth and data lag to operators and to downstream consumers

Hints

Hint 1

Start with the rate-limit scope question. If the cap is per-credential rather than global, your architecture changes significantly — you might run isolated worker pools per credential instead of a single shared limiter.

Hint 2

A Redis token bucket or sliding-window counter is the standard answer for cross-process rate limiting. Walk through why a local in-process counter breaks under horizontal scaling before proposing the centralized solution.

Hint 3

Do the math out loud: 3 req/s × 60s × 60min = 10,800 req/hr. If you pull 1,000 records per page, that's 10.8 million records per hour maximum throughput. State that number, then derive what page size and freshness SLA you can actually meet.