Guide / Revision kit
28. Self-test question bank
Cover the answer column and answer out loud in under 30 seconds. If you can’t, re-read the section in brackets.
| # | Question | Short answer |
|---|---|---|
| 1 | Why delete the cache key instead of updating it on write? | Deletes are idempotent and avoid racing writers leaving a stale value (2.3) |
| 2 | What is a cache stampede and two fixes? | Hot key expires, many requests hit DB; single-flight lock, serve stale while refreshing (2.4) |
| 3 | Composite index for WHERE user_id=? AND status=? ORDER BY created_at? | (user_id, status, created_at) — equality first, sort last (4.2) |
| 4 | Why is OFFSET 100000 slow and what replaces it? | DB reads and discards all skipped rows; keyset/cursor pagination (1.3, 4.3) |
| 5 | How do you compute top spenders over 2B orders? | Pre-aggregate on write or stream (Kafka → Flink → sorted set), or warehouse; never on OLTP request path (4.4) |
| 6 | Lost update vs write skew? | Lost update: two read-modify-writes overwrite; write skew: two transactions each keep an invariant locally but break it together (4.5) |
| 7 | What does R + W > N guarantee? | Read and write quorums overlap, so reads see the latest acknowledged write (5.4) |
| 8 | CAP in one sentence? | During a network partition, choose consistency (reject) or availability (serve possibly stale) (5.3) |
| 9 | How does read-your-writes break with replicas and how to fix it? | Replica lag shows old data; read from primary briefly after a write or wait for the write’s LSN (5.1) |
| 10 | Kafka ordering guarantee? | Only within a partition; key by entity (6.2) |
| 11 | What’s the transactional outbox? | Write the event in the same DB transaction; a relay publishes it (6.4) |
| 12 | How do you guarantee one charge per order? | Idempotency key + unique constraint, guarded state transitions, gateway idempotency key, webhook dedupe, reconciliation (7.3) |
| 13 | Why aren’t Redis locks safe for correctness alone? | GC pauses/expiry and async failover allow two holders; need fencing tokens (8.3) |
| 14 | Why consistent hashing? | Adding/removing a node moves only ~1/N keys (8.6) |
| 15 | What’s a circuit breaker? | Fail fast after repeated errors, probe in half-open, close when healthy (9.1) |
| 16 | How do you recover from a WebSocket drop? | Backoff + jitter, re-auth, send last sequence, replay or snapshot, resend unacked with same IDs (9.2) |
| 17 | RPO vs RTO? | Data you can lose vs time you can be down (9.3) |
| 18 | Token bucket vs fixed window? | Token bucket allows bounded bursts; fixed window allows 2× burst at boundaries (10.1) |
| 19 | Fan-out on write vs read? | Precompute feeds (fast reads, costly writes) vs build on read; hybrid for celebrities (11.4) |
| 20 | What are prefill and decode? | Prefill processes the prompt (sets TTFT); decode generates token by token (sets tokens/s) (14.2) |
| 21 | Why put stable prompt content first? | Enables provider prompt caching of the prefix (14.2, 15.3) |
| 22 | HNSW strengths and weaknesses? | Best recall/latency, incremental inserts; memory-heavy, poor deletes, selective filters hurt (16.2) |
| 23 | Pre-filtering vs post-filtering in vector search? | Post-filter returns too few with selective filters; pre-filter can break graph search; use filter-aware engines (16.2) |
| 24 | When pgvector vs Pinecone? | pgvector if already on Postgres and < ~10–50M vectors; managed engine for scale/QPS/zero ops (16.3) |
| 25 | What happens when you change embedding models? | Must re-embed everything; build a new index and switch an alias (16.1, 16.6) |
| 26 | Why hybrid search? | Dense misses exact terms (SKUs, names); BM25 catches them; fuse with RRF (17.3) |
| 27 | What does a reranker do? | Cross-encoder scores query+chunk jointly to reorder top candidates; big precision gain (17.1) |
| 28 | Retrieval vs generation metrics in RAG? | Recall@k, MRR, nDCG vs faithfulness, answer relevance (17.4) |
| 29 | Where must permission filtering happen in RAG? | Inside the retrieval query, before content reaches the LLM (17.5, 22.2) |
| 30 | When GraphRAG over vector RAG? | Multi-hop relationship questions and corpus-wide summaries; worth the indexing cost only then (18.3) |
| 31 | Workflow vs agent? | Known steps → workflow; open-ended tool use → agent (19) |
| 32 | What is MCP? | Open protocol for apps to connect to tools/resources/prompts via servers (19.3) |
| 33 | Three LLM-judge biases? | Position, verbosity, self-preference (20.3) |
| 34 | Indirect prompt injection? | Malicious instructions inside retrieved/tool content; defend with least privilege, data delimiting, approvals (20.7) |
| 35 | Semantic cache risk? | Similar-looking queries with different meaning get a wrong cached answer (21.2) |
| 36 | RAG vs fine-tuning? | RAG for changing facts and citations; fine-tuning for behaviour, format, style (17.6, 21.6) |
| 37 | What is LoRA? | Train small low-rank adapter matrices instead of all weights (21.6) |
| 38 | Voice agent latency target and main levers? | ~500–800 ms; stream all stages, fast model, start TTS on first sentence, fillers (19.7, 22.3) |
| 39 | Barge-in handling? | Stop TTS immediately, truncate history to what was spoken, process new input (22.3) |
| 40 | OT vs CRDT? | OT transforms ops via a central server; CRDTs merge deterministically anywhere (10.7) |
| 41 | What is the difference between TCP and UDP and when do you pick each? | TCP: reliable, ordered, congestion-controlled; use when correctness matters. UDP: no guarantees, no handshake; use when freshness beats completeness (calls, games, DNS, QUIC) (1.2) |
| 42 | 401 vs 403 vs 404 vs 409 vs 429? | Not authenticated / authenticated but not allowed / unknown (or hidden) resource / state conflict / rate limited, with Retry-After (1.3) |
| 43 | How do you make a POST retry-safe? | Idempotency-Key stored under a unique constraint with the saved response; same key + different body → 409/422 (1.3, 7) |
| 44 | L4 vs L7 load balancer? | L4 balances connections by IP/port (fast, any protocol); L7 reads HTTP and routes by host/path/header, terminates TLS, retries (1.4) |
| 45 | Which LB algorithm for uneven request durations? For cache affinity? | Least connections / least outstanding requests / P2C; consistent hashing (1.4) |
| 46 | In what order do you scale a database? | Indexes and queries → pooling → cache → vertical → replicas → move analytics out → partition → functional split → shard last (1.5) |
| 47 | What does a good 429 response contain and how should a client react? | 429 + Retry-After + rate-limit headers + error body; client waits, backs off with jitter, retries only idempotent calls with a budget (1.6) |
| 48 | Why can’t a hit ratio alone tell you the cache is healthy? | 1% misses of 100K QPS is still 1K QPS on the DB; misses can be correlated (stampedes, cold nodes) and expensive; watch absolute miss rate, evictions and origin load (2) |
| 49 | KV cache bytes per token for 32 layers, 8 KV heads, head dim 128, fp16? | 2×32×8×128×2 B = 128 KB per token (transformer internals) |
| 50 | What is continuous batching and why does it matter? | Add and remove sequences every decode step so the GPU stays full (LLM serving) |
| 51 | LoRA in one sentence? | Train small low-rank adapters on a frozen base model (model adaptation) |
| 52 | How do you guarantee one driver per ride? | Atomic compare-and-set on driver and trip state (ride-hailing) |
| 53 | How do you avoid double-booking a seat? | Conditional update / unique constraint; holds with expiry (ticket booking) |
| 54 | What do you do when a payment call times out? | Mark unknown, never retry with a new key; reconcile by key/webhook (payment system) |
| 55 | Error budget for 99.9% over 30 days? | About 43 minutes (SRE and operations) |
| 56 | Orchestration vs choreography saga? | Central coordinator vs services reacting to events (microservice patterns) |
Finished this page?Mark it done to track your progress across the guide.