Posts tagged “interview”

  1. 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.

    · 6 min read · System Design

  2. 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.

    · 6 min read · System Design

  3. 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.

    · 6 min read · System Design

  4. 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.

    · 7 min read · System Design

  5. 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.

    · 6 min read · System Design

  6. 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.

    · 6 min read · System Design

  7. 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.

    · 6 min read · System Design

  8. 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.

    · 7 min read · System Design