Appearance
Platform Designs
31. How would you design a centralized logging system?
The short answer
Every service writes structured JSON logs to stdout. An agent on each node, such as Fluent Bit, Vector or the OpenTelemetry Collector, tails them, adds metadata like service, pod and region, and sends batches to a buffer, usually Kafka, so spikes and storage outages do not lose logs. Indexers consume from the buffer and write to a searchable store, such as Elasticsearch, OpenSearch or Loki, split into time-based indices with hot, warm and cold tiers and retention by log type. A query UI searches by trace ID, service, level and text. Redact secrets at the source and control who can read which logs.
Estimates: 500 services, 2 million log lines per second at 500 bytes ≈ 1 GB per second ≈ 86 TB a day raw. Compression of 5 to 10 times and sampling of noisy debug logs bring it down a lot, and retention tiers decide the cost.
| Deep dive | Design |
|---|---|
| Volume and cost | Sample debug logs; drop health-check noise at the agent; short hot retention |
| Search | Index common fields such as service, level and trace ID; full-text only where needed |
| Correlation | Trace ID on every line (correlation IDs) |
| Back-pressure | Agents buffer to disk; Kafka absorbs bursts |
| Security | Redaction at the source; access per team; audit logs kept separately (audit logging) |
32. How would you design a monitoring system?
The short answer
Services expose metrics, counters, gauges and histograms with labels such as service and route, which are scraped by Prometheus-style collectors or pushed through the OpenTelemetry Collector into a time-series database built for many writes and range queries. Recording rules precompute common aggregates. An alerting engine evaluates rules, especially SLO burn-rate rules, every minute and routes alerts by severity and owner to paging, chat or tickets, with grouping and silences. Dashboards show golden signals. Watch label cardinality: a label such as user ID can create millions of series and break the system.
| Part | Design |
|---|---|
| Collection | Pull scraping every 15 to 30 seconds; push for short-lived jobs |
| Storage | Time-series database; downsample old data, such as 1-minute points after 30 days |
| Scale | Shard by metric or tenant; long-term storage in object storage |
| Alerts | SLO burn rates on user-facing symptoms; each with an owner and runbook (alerting) |
| Routing | Critical to paging, warnings to chat, the rest to tickets; deduplicate and group |
| Meta-monitoring | A separate, simple check that the monitoring system itself is alive |
Cardinality, with numbers. A metric labelled by 50 routes, 5 status codes and 20 instances is 5,000 series, which is fine. Add a user_id label with a million users and it becomes 5 billion series, which no system will hold. Put per-user detail in logs or traces, not metric labels.
33. How would you design distributed caching?
The short answer
Layer it: a CDN for public responses, a small in-process cache for the hottest keys, and a shared Redis cluster with replicas as the main cache, using cache-aside with TTLs and invalidation driven by database change events. Design keys with versions and tenant IDs, protect the database from stampedes with single-flight rebuilds and jittered TTLs, handle hot keys with local copies, and treat the cache as optional, with timeouts and a fallback when Redis is unavailable. Measure hit rate, latency and evictions.
The complete design, with a diagram and the numbers that justify it, is in designing distributed caching. The building blocks are cache-aside, TTLs, Redis Cluster and stampedes.
34. How would you design a backend that handles millions of requests reliably?
The short answer
Start with the numbers: a million requests a day is about 12 per second; a million per minute is about 17,000 per second, which needs real scale. Either way the shape is the same: stateless services autoscaled across zones behind load balancers; a CDN and caches absorbing most reads; a well-indexed database with replicas, partitioned only when writes demand it; queues for slow and bursty work; timeouts, retries with budgets, circuit breakers and rate limits everywhere; idempotent writes; safe deploys with rollback; and SLO-based monitoring. Reliability comes from removing single points of failure and planning for each dependency failing.
| Layer | At 17,000 requests per second |
|---|---|
| Edge | CDN serving most public reads; WAF and rate limits |
| API | 20 to 40 stateless instances across 3 zones, autoscaled on CPU and latency |
| Cache | Redis cluster; 90%+ hit rate keeps the database near 1,700 per second |
| Database | Primary plus replicas; reads on replicas; pooled connections through PgBouncer |
| Async | Queues for notifications, exports, search indexing |
| Resilience | Timeouts, breakers, bulkheads, load shedding (resilience) |
| Operations | Canary deploys, error-budget alerts, runbooks, game days |
The single-region version for one million requests a day is worked through in handling a million requests a day.