API design for large systems
36 questions in 8 subtopics.
APIs are the contracts between services, client apps and partners, and at scale their design decides cost, reliability and how fast teams can change. A choice made for the first client, such as offset pagination, a missing idempotency key or a breaking field change, becomes expensive once thousands of integrations depend on it. Production problems show up as CDN caches that stop working, calls without deadlines, deep pages that fail, double charges after retries, rate limits that do not protect, silent schema corruption, slow webhook endpoints that delay everyone, stuck background jobs and fan-out that ruins tail latency. The questions cover choosing between REST, gRPC and GraphQL, pagination, idempotency keys, rate limiting algorithms, versioning and compatibility, webhooks, long-running operations and backends for frontends, from mechanics to incidents to platform strategy.
REST, gRPC and GraphQL trade-offs
REST over HTTP with JSON, gRPC with Protocol Buffers over HTTP/2, and GraphQL with a typed query language each fit different callers. They differ in caching, tooling, payload size, streaming, browser support and operational needs. Understand which style suits public partners, internal high-volume calls and varied client screens, what changes when a system moves from one style to another, and why every public style is a long-term commitment.
Large systems usually offer more than one API style: REST over HTTP with JSON, gRPC with Protocol Buffers over HTTP/2, and GraphQL with a typed schema. Each fits some callers better than others.
Which style would you choose for a public partner API, internal high-volume service-to-service calls, and a mobile app whose screens need varied data, and which properties drive each choice?A retail site moved its product pages from REST endpoints to one GraphQL endpoint. Since the release the CDN hit ratio for product data fell from 92 percent to almost zero, and origin traffic grew tenfold during a sale.
Explain why the CDN stopped helping, and how you would make GraphQL responses cacheable again.A team migrated calls between a checkout service and an inventory service from REST to gRPC in Java. During a partial inventory outage, checkout threads piled up waiting for minutes and the service fell over, although the REST client used to time out after 2 seconds.
Why did this happen, and how should deadlines, retries and error codes be handled with gRPC?A platform of 120 services talks over REST with JSON at 80,000 requests per second at peak. Profiling shows 25 to 30 percent of service CPU spent on JSON serialisation and parsing, and the cloud bill is under pressure.
How do you decide whether moving internal calls to gRPC is worth it, and how would you roll it out?A company's public REST API serves 3,000 integrations. Large customers now ask for GraphQL for flexible reads and gRPC streaming for real-time updates, and two teams have started building them separately.
As the senior technical leader, how do you decide which API styles the public platform offers, and how do you keep several styles consistent over years?Pagination at scale
Pagination splits large result sets into pages. Offsets become slow and inconsistent as data grows, so large APIs use opaque cursors that encode the position in a sort order. Understand how cursors are built and validated, why search engines cap deep paging, how pagination works across shards, and why bulk synchronisation is better served by change feeds or exports than by paging through lists.
Cursor pagination returns a token that marks where the next page starts. Large APIs make the cursor opaque: clients pass it back unchanged and cannot build or edit it.
Why should a cursor be opaque, and how would you encode and validate one in a Java service for a list sorted bycreatedAt and id?Orders are sharded by customer id across 16 database shards, but an admin API must list all orders by creation time, newest first, with pages of 50.
How does pagination work across shards, why do offsets get expensive, and how would you design the cursor?A partner exports all of its orders through GET /orders?page=N&size=100, which is served by Elasticsearch. Around page 101 every request fails, and the logs show: Result window is too large, from + size must be less than or equal to: [10000].
Explain the limit and redesign the endpoint for deep paging and exports.4,000 partners keep local copies of their catalogue in sync with your platform by paging through GET /products?updatedSince=... every 5 minutes. Partners report missing deletions and occasional missed updates, and the sync queries are 30 percent of database load.
Idempotency keys for APIs
An idempotency key lets a client retry a non-idempotent request, such as creating a payment, without the server performing the operation twice. The server stores each key with the request fingerprint, the state and the response for a retry window. Understand the expected responses for repeats, conflicts and mismatched bodies, how clients and gateways break the scheme, how to store keys at high volume, and what happens during regional failover.
An idempotency key is a unique value a client sends with a non-idempotent request, such as POST, so the server can recognise a retry. The details of how the server treats the key decide whether retries are really safe.
What should the server do when the same key arrives again with the same body, with a different body, and while the first request is still running? What exactly does it store?A payment API supports Idempotency-Key, yet support sees about 30 double charges a day, all from the mobile app. The API gateway retries POSTs once on timeout, and the app's HTTP layer retries failed requests up to three times.
How do you find where the duplicates come from, and what do you fix on the client, the gateway and the server?An order API stores idempotency records in a PostgreSQL table at 30,000 writes per second. The table reached 2 billion rows, nightly DELETEs of expired keys cause replica lag and bloat, and p99 latency of the order endpoint doubled.
How would you redesign storage of idempotency records at this volume?A payments API runs active-passive in two regions, and idempotency records are stored per region with asynchronous replication. After a regional failover, clients that retried in-flight requests produced 1,200 duplicate payments.
Explain how the failover produced duplicates, and design idempotency that survives region failures.A platform team proposes to offer idempotency as a gateway feature: the gateway stores keys and responses for every POST, so services need no code for it. Some service owners say only the service can know when an operation took effect.
As the senior technical leader, how do you evaluate the proposal, and what do you make the platform's responsibility versus each service's?Rate limiting algorithms
Rate limiting decides which requests to accept based on recent traffic, using algorithms such as token bucket, leaky bucket, fixed window, sliding window and concurrency limits. Each treats bursts, boundaries and distributed enforcement differently. Understand the burst arithmetic, why fixed windows synchronise clients, how to enforce a global limit across many nodes, why rate limits do not protect against slow dependencies, and how to limit expensive requests fairly.
Rate limiters decide whether a request may pass based on recent traffic. The token bucket and the leaky bucket sound alike but treat bursts very differently.
With a token bucket of capacity 100 refilled at 10 tokens per second, how many requests can a client send in its first 10 seconds after being idle? How does a leaky bucket with the same rate behave, and when would you choose each?A public API limits each key to 600 requests per minute with a fixed-window counter that resets at the start of each clock minute. Graphs show request spikes and a wave of 429 responses in the first two seconds of every minute, while the rest of the minute is quiet.
What is going on, and how would you change the algorithm and the responses?A search service has a fixed rate limit of 2,000 requests per second. During a slowdown of its database, latency rose from 50 ms to 2 seconds while traffic stayed under the limit, and the service still collapsed with exhausted thread pools.
Why did the rate limit not protect the service, and how do concurrency limits and adaptive limiters work?An API gateway enforces 1,000 requests per second per customer by giving each of its 10 nodes a local limit of 100 per second, with no shared state. After autoscaling to 40 nodes, large customers got four times their limit, while on quiet nights some were throttled far below it.
Explain both effects and compare the ways to enforce a global limit across many nodes.A SaaS API limits each customer to 100 requests per second. One customer stays within the limit but calls a report export endpoint that runs 20-second database queries, and at peak those calls use 70 percent of database CPU, slowing everyone.
How do you change rate limiting so that expensive requests are limited fairly, and how do you roll the change out to existing customers?API versioning and compatibility
Clients and servers are deployed at different times, so APIs must evolve without breaking the versions already in use. Compatibility rules depend on the format: field numbers in Protocol Buffers, field names and types in JSON. Understand which changes are safe, how silent corruption happens, how to manage mobile clients that never upgrade, and how to retire an old version with signals, brownouts and clear dates.
With gRPC and other Protocol Buffers APIs, compatibility depends on field numbers rather than field names, because the binary format carries only numbers and types. Services and clients deploy at different times, so old and new schemas meet all the time.
Which changes to a .proto message are safe for old and new readers, which are breaking, and how do reserved fields and unknown fields help?After a release of a gRPC pricing service, a few older clients started showing wrong discounts, with no errors anywhere. The diff shows that field 5, discount_percent, had been deleted months earlier, and the new release added field 5 as discount_amount_cents.
Explain why nothing failed loudly, how to repair the situation, and how to prevent it.A mobile banking app talks to a public REST API. Telemetry shows 14 percent of requests still come from app versions over 2 years old, which cannot be updated remotely, and a planned change to the account response would crash those versions.
How do you evolve the API while such old clients are in use, and what do you build so this is manageable in future?A public API's v1 is scheduled for shutdown in 90 days. 400 integrations still call it, about 9 percent of traffic, and several large customers have not replied to emails. Leadership will not accept a big outage on the shutdown date.
How do you run the retirement so it finishes on time without surprising customers?Webhooks and callbacks
Webhooks push event notifications to URLs that customers register, so they do not have to poll. Delivery is usually at least once and unordered, and it runs across the public internet to endpoints the platform does not control. Understand signing and replay protection, isolation of slow endpoints, how receivers handle duplicates and ordering, security risks of customer-supplied URLs, and alternatives such as event feeds.
Webhooks are HTTP callbacks a platform sends to a customer's URL when something happens. Because anyone can send a request to that URL, the receiver must verify each delivery came from the platform and is not an old message replayed.
How should webhook payloads be signed and verified? Outline the verification code in Java.A platform delivers 30 million webhooks a day to 15,000 customer endpoints using a shared pool of 200 delivery workers. One large customer's endpoint started responding after 30 seconds, and webhooks for all other customers were delayed by up to 2 hours.
Why did one slow endpoint delay everyone, and how would you redesign delivery?An order service receives webhooks from a payment provider. Some orders end in PENDING although the payment succeeded: the logs show payment.succeeded processed before payment.processing for the same payment, and a few events arrived twice.
A SaaS company wants to let customers register webhook URLs for 40 event types. Expected volume is 50 million events a day, customers want to replay missed events, and the security team worries about customer-supplied URLs.
Design the webhook platform, including how events flow from services to endpoints, replay, and protection against abuse of the URLs.The company's webhook system grew to be its main integration channel, but large customers complain about missed events and firewall rules, and smaller ones cannot run public endpoints at all. Product asks what the integration strategy should be for the next five years.
As the senior technical leader, how do you decide between webhooks, polling or event feed APIs, and managed event streaming offered to customers?Long-running and asynchronous operations
Some API operations take too long for a single request, so the server accepts the work, returns 202 with an operation resource, and the client polls or receives a callback. Understand how to keep polling cheap, how background jobs survive worker restarts with leases, how to deliver very large results and share capacity fairly between tenants, and when an API should be asynchronous by default.
An API starts report generation with POST /reports, returns 202 Accepted with a status URL, and clients poll that URL. After a popular client library update, the status endpoint receives 40,000 requests per second, most from clients polling every 100 ms.
How do you control polling load while keeping the asynchronous pattern, and what should the status response tell the client?Asynchronous export jobs run on worker pods that take work from a jobs table. After each deployment, about 3 percent of jobs stay in RUNNING forever, and clients poll them indefinitely.
Explain why jobs get stuck and how to make job execution robust to workers dying.A B2B analytics platform lets customers export data sets of up to 200 GB through its API. Today exports run inside request threads and time out, and one large tenant's exports can occupy all export capacity for hours.
Design the export API and backend, including how results are delivered and how capacity is shared fairly between tenants.A new public platform API is being designed. One group of architects wants every mutating endpoint to be asynchronous, returning 202 and an operation resource, for uniformity and resilience; another group says this makes simple calls much harder for customers.
As the senior technical leader, how do you decide between synchronous and asynchronous by default, and what rules do you set?Backends for frontends and API composition
A backend for frontend is an API layer built for one client experience that composes domain services into responses shaped for its screens. Composition can also be done with a federated GraphQL graph or with precomputed view services. Understand what BFFs solve and cost, why fan-out to many services makes tail latency worse, how duplicated logic creeps into several BFFs, and how team structure shapes the composition strategy.
A backend for frontend (BFF) is a server-side API layer built for one client experience, such as the iOS app or the web site. It calls domain services and shapes their data for that client's screens.
What problems does a BFF solve compared with clients calling services directly or one general-purpose API gateway, and what problems does it bring?The home screen BFF calls 12 services in parallel. Each service has a p99 of 300 ms and a median of 40 ms, yet the BFF's p99 is above 900 ms, and one in ten home screen loads feels slow.
Explain why fan-out makes tail latency so much worse, and how you would bring the BFF's p99 down.Over four years the company built six BFFs (iOS, Android, web, partner portal, TV and smartwatch). Each reimplements pricing display and eligibility checks slightly differently, and a recent change to the loyalty service broke four of them in production.
How do you restore consistency and stability without losing the speed BFFs gave the client teams?The company has 400 engineers, 70 domain services and five client platforms. Some leaders want a federated GraphQL supergraph owned jointly by domain teams, others want to keep per-client BFFs, and a third group wants precomputed view services.
As the senior technical leader, how do you decide the long-term composition strategy, and which organisational choices come with it?