System Design
22 posts on System Design from funGyaan: curious questions answered simply, readable as a series from part 1 or newest first.
-
How do you deliver webhooks so no event is ever lost?
Write every event to an outbox, retry with backoff and jitter for a day or more, sign each request with a timestamp, and let receivers replay what they missed. Receivers answer fast, deduplicate by event ID and never trust order. The design, and the quiet failure it prevents.
-
How does a voice AI agent reply in under a second?
By never waiting for anything to finish: streaming speech recognition, a turn detector, a model that streams its first words and speech synthesis that starts speaking them at once. The latency budget, the tricks that win back time, and why knowing you've finished is the hard part.
-
What happens when you call a company's support number?
A support call is two journeys: SIP signalling sets it up, RTP packets carry your voice. Between them sit a border controller, a media server running the menu, a queue that picks the agent, and a recorder. Here is the whole path, and the bug that hides in the gap.
-
What happens when you type a search into Google and press Enter?
A tour from the keystroke to the painted page: the browser, DNS, TCP/TLS vs QUIC, the edge, a query fanned out to thousands of index servers, and the response streamed back. What each step costs, what can fail, and why the slowest server decides how fast the page is.
-
Why did adding a cache make our data wrong?
A cache is a second copy of your data with its own rules, and every way it can disagree with the database shows up as a bug. Five failure modes measured with Redis in front of PostgreSQL, and the fix for each.
-
How do you generate unique IDs across many servers?
Inserting 5 million rows with random UUIDv4 keys took 34 s and left a 196 MB index at 69% fill; time-ordered UUIDv7 took 21 s with a 150 MB index at 90%; plain bigint 24 s and 107 MB. Database sequences, UUIDv4, UUIDv7 and Snowflake-style IDs compared, measured on PostgreSQL, with when to use which.
-
A user says a page has started lagging: how do you debug it end to end?
Narrow it down before you open a profiler: who, which page, since when. Then measure one layer at a time (browser, network, server, database, dependencies) until one of them owns the time. Five server-side causes measured with OpenTelemetry traces, and the signature each leaves.
-
How do you scale an API?
Find the bottleneck first, then use the cheapest lever that removes it: fix the query, cache the read, pool the connections, add replicas, queue the slow writes, limit each client. Each lever measured on one machine: what it bought, and what it cost.
-
How do you migrate a live database without downtime?
Most outages during migrations aren't failed migrations; they're migrations that held a lock while traffic queued behind them. Measured on a 5M-row table under load: one-step changes that stalled every request for 2-8 seconds, and the online versions that stalled them for a fraction of a second…
-
When should a write go through a queue instead of the API?
Queue the work behind a write when it's slow, unreliable or can finish after you answer; keep it synchronous when the caller needs the result. And never publish from the request itself: use an outbox.
-
How do you handle file uploads and serve them fast?
Let clients upload straight to object storage with short-lived pre-signed URLs, so files never pass through your app servers. Process them asynchronously (scan, resize, extract), serve them through a CDN, and keep private files private with signed download URLs.
-
How do you build search autocomplete?
For a catalogue of thousands of items, a sorted list and a binary search answer prefixes in microseconds. For popularity-ranked suggestions over millions of queries, precompute the top few completions for every prefix. Typo tolerance, debouncing and caching matter as much as the data structure.
-
Where does the time go in a manual order process, and what can AI actually remove?
Quotation turnaround in B2B manufacturing went from 45 days to 5. Most of the time wasn't in any one step; it was in waiting between steps and in re-typing the same information. Where AI helps (reading messy documents, matching parts, routing exceptions), where it doesn't, and how to automate…
-
How do you design payments so nobody is charged twice?
Idempotency keys on every money-moving request, an explicit state machine for each payment, a double-entry ledger that never updates balances in place, webhooks treated as the source of truth, and daily reconciliation against the provider. Each one closes a different way money goes wrong.
-
How do you design a notification system?
One API that records the intent to notify, then a queue per channel (email, push, SMS, in-app) with its own retries and rate limits. User preferences, deduplication, quiet hours and digests sit before the queues; provider webhooks for bounces and complaints sit after them.
-
REST vs GraphQL vs gRPC for internal services: which one?
REST for public and simple APIs, GraphQL where many clients need different shapes of the same data, gRPC between your own services when latency and strict contracts matter. What each one is good at, what it costs, and how to choose per boundary, not per company.
-
How do you build real-time chat?
WebSockets for the live connection, but the database is the source of truth: messages get a server-assigned sequence per conversation, clients acknowledge what they've seen, and reconnecting clients fetch what they missed. Polling, long polling and server-sent events still have their place.
-
How do you build a news feed: fan-out on write or on read?
Fan-out on write precomputes each follower's timeline, so reads are instant, but one post from an account with millions of followers means millions of writes. Fan-out on read is cheap to write and expensive to read. Large feeds use both: push for most accounts, pull for the very popular ones.
-
How do you design a URL shortener?
A counter encoded in base62 gives short, unique codes without collision checks; a cache in front of the database serves almost every redirect. The real decisions are 301 vs 302, how to count clicks without slowing redirects, and how to stop abuse.
-
How do you make LLM document extraction reliable enough to automate?
Why I route extracted documents by their weakest field, treat model output as untrusted, and judge the system by straight-through rate and error rate among auto-accepted documents.
-
Monolith vs microservices vs cell-based architecture: which one, when?
Start with a modular monolith, split out only the parts that scale or fail differently, and reach for cells when one customer's bad day must not become everyone's. What each architecture fixes, what it costs, and the signals that say it's time to change.
-
How do you keep tenants apart when they share one database?
How I let Postgres, not application code, keep tenants apart, so a forgotten tenant filter returns nothing instead of another customer's data: FORCE, non-owner roles, transaction-local settings, fail-closed policies, and tests that prove it.