Kayavak / Recaps / Capstone
Recaps · Volume 19
Capstone
The revision sheet of every chapter, on one page: the key ideas, the numbers worth knowing, the pitfalls and the words. Use it before an interview, after a chapter, or to find which chapter to reread. Each title opens its chapter; below each sheet are its exercises, companion and TiffinBox stage, and the misconceptions the companion corrects.
211A
Key ideas
- One serious system teaches integration: contracts, ownership, deployments, cascading failures.
- Requirements as journeys (never fail / fast / can be late) and numbers (availability, latency, RPO/RTO, cost).
- Estimate first: most of TiffinBox fits one database; tracking and AI shape the design.
- Modular monolith with enforced module boundaries; extract only with a reason (the tracking gateway).
- Call when the caller needs the answer; publish (via an outbox) when others just react.
- Walking skeleton first; every milestone ends deployed and observed; ADRs for every contestable decision.
Numbers to remember
- 99.9% ≈ 43 minutes of outage a month.
- Lab: N+1 (21 round trips) 732/s vs join 2,715/s vs cache 4,173/s; proxy hop ~0.3 ms.
- Cross-zone round trip 0.5–1 ms; 20 extra round trips ≈ 10–20 ms.
Pitfalls
- Over-engineering for scale; integration at the end.
- Shared tables across modules; unenforced boundaries.
- Requirements without numbers; undocumented decisions.
Glossary
- Walking skeleton: thinnest deployed, observed end-to-end slice.
- Modular monolith: one deployable with enforced internal module boundaries.
- Derived data: data rebuildable from a source of truth (search and vector indexes).
- Outbox: events written in the same transaction as the change, published later.
- ADR: architecture decision record.
211B
Key ideas
- Generated, validated API client from the shared contract; explicit request states.
- A component library with accessibility built into its primitives; axe plus manual walkthroughs.
- Mobile-first responsive layout; container queries; no hover-only actions.
- URL state for what the user is looking at; a server-state cache for backend data; little client state.
- BFF pattern: tokens server-side, HTTP-only cookies, CSRF protection.
- SSE for one-way live updates with resume, heartbeats, backoff with jitter and a polling fallback.
- Few, reliable Playwright journeys; budgets in CI; field Core Web Vitals per release.
Numbers to remember
- Lab: poll 5 s → mean 2 s delay; poll 1 s → 482 ms; SSE/WebSocket < 1 ms.
- 1,000 users polling 1/s = 20,000 requests in 20 s, ~10% of a core; 1,000 idle SSE ≈ 0 CPU, ~12 KB each.
- Vitals at p75: LCP ≤ 2.5 s, INP ≤ 200 ms, CLS ≤ 0.1; touch targets ≥ 44 px; text contrast ≥ 4.5:1.
Pitfalls
- Hand-written types; server data in global stores; div soup; tokens in storage; polling for realtime; lab-only performance.
Glossary
- BFF: backend-for-frontend, holding tokens and sessions for the browser app.
- SSE: server-sent events, a one-way HTTP stream with automatic reconnection.
- Stale time: how long cached server data counts as fresh.
- Optimistic update: showing a change before the server confirms it, with rollback.
- RUM: real-user monitoring.
211C
Key ideas
- Modules with
api / web / application / domain / persistence; transactions start in use cases.
- REST with problem details, idempotency keys, ETag/If-Match, keyset pagination, additive evolution.
- Validation at three levels: edge (shape), domain (rules), database (invariants).
- No remote calls in transactions; lock or conditional statements for check-then-act; outbox for events.
- Authorization coarse by role, fine in queries; the assistant acts as the user.
- Every outbound call: timeout, bulkhead, breaker or fallback; retries only when safe, with jitter and budgets.
- JSON logs with trace IDs and no personal data; OpenTelemetry across HTTP and Kafka.
Numbers to remember
- Lab: no timeout →
/healthy 0 successes; timeout → 48/s at 201 ms; breaker → 4,330/s at 2.2 ms; virtual threads → /healthy fine, /quote still 5 s.
- Nagle + delayed ACK ≈ 40 ms floor per request;
TCP_NODELAY fixed it (227/s → 29,976/s).
- 3 layers × 3 retries = up to 27 calls for one failure.
Pitfalls
- Remote calls in transactions; proxy self-invocation; unbounded concurrency; retrying non-idempotent calls; business refusals logged as errors.
Glossary
- Problem details: RFC 9457 error format.
- Idempotency key: client-chosen ID making retries of one request safe.
- Bulkhead: isolated resource pool per dependency.
- Circuit breaker: stops calls to a failing dependency for a while.
- JEP 491: removed virtual-thread pinning inside
synchronized (JDK 24).
211D
Key ideas
- PostgreSQL and object storage are sources of truth; Redis, search and vector indexes are derived and rebuildable.
- Schema per module with role grants; migrations with expand/contract, lock timeouts, concurrent indexes and batched backfills.
- Indexes from real queries, verified with plans at production size; small pools with wait timeouts.
- Read-your-writes despite replica lag; PITR with timed drills.
- Redis: TTL with jitter, stampede protection, fast failure and fallback, eviction policy.
- Files: private buckets, presigned upload and download, content validation, scanning, lifecycle and versioning.
- Search: PostgreSQL full-text + trigrams first; a search engine fed by events when needed; alias swaps.
- Retention and erasure across every copy.
Numbers to remember
- Lab: unindexed substring 214 ms; trigram 26 ms; full-text 2.7 ms; ranked top 10 27 ms; typo → 0 rows; trigram similarity 47 ms.
- Index sizes: full-text 4.8 MB, trigram 13 MB for a 46 MB table.
- Embeddings: 768 × 4 bytes ≈ 3 KB per chunk.
Pitfalls
- Caches as sources of truth; substring search without trigrams; big pools; public buckets; personal data left in derived stores.
Glossary
- GIN: generalised inverted index.
- Lexeme: a normalised word in full-text search.
- Trigram: a three-character fragment used for similarity.
- Presigned URL: a time-limited signed link to one object.
- HNSW: graph-based approximate nearest-neighbour index.
211E
Key ideas
- Events are facts; keys choose ordering; partitions give parallelism.
- RF 3,
min.insync.replicas=2, acks=all, idempotent producers; retention covering replay.
- Envelope with event ID, type, version, time, key and trace context; schemas in a registry with backward compatibility; upcasters for old versions.
- Outbox (poller or CDC) with outbox-age monitoring.
- Idempotent consumers: processed-event records in the same transaction, natural idempotency, idempotent side effects; commit offsets after processing.
- Bounded in-place retries, retry topics, DLQ with alerts and redrive; never block a partition.
- Replay to rebuild or create projections, with side effects off.
Numbers to remember
- Lab: block policy stuck at 150,001 of 200,000; DLQ policy processed all at ~161k/s; new projection in 1.2 s; duplicate DLQ entry on a second replay.
Pitfalls
- Disguised commands; keys that scramble order; infinite retries; replays with side effects; personal data in events.
Glossary
- Partition: an ordered, append-only log; the unit of parallelism.
- Consumer group: consumers sharing a topic's partitions, each partition read by one member.
- Offset: a consumer's position in a partition.
- Compacted topic: keeps the latest value per key.
- Upcaster: code converting an old event version to the current one.
211F
Key ideas
- Map questions to techniques: documents → RAG with citations; live data → tools as the user; multi-step → a bounded agent; out of scope → refuse.
- Never invent allergen claims; abstain when evidence is missing.
- Gateway: providers, timeouts, fallbacks, breakers, limits, streaming, tracing with cost.
- Ingestion by structure, versioned; hybrid retrieval, filters, reranking.
- Validate structured output, one retry, fallback; never execute output.
- Tools allow-listed, user-scoped, confirmed and idempotent for writes.
- Evaluation sets of hundreds of questions, paired comparisons, zero-tolerance checks, CI gates, online sampling.
- Security outside the prompt: permissions, allow-lists, confirmations, sanitising, budgets.
Numbers to remember
- Validate + 1 retry: 90% → 99% valid for ~1.10 calls.
- Detecting 85% → 80%: 100 questions 34%, 400 questions 83%, 800 questions 98%.
Pitfalls
- RAG for live data; fixed-size chunks; tiny eval sets; prompt-only security; agents everywhere.
Glossary
- Reciprocal rank fusion: combining rankings by summing 1/(k + rank).
- Cross-encoder reranker: scores a question–passage pair jointly.
- Abstention: declining to answer when evidence is insufficient.
- LLM-as-judge: a model grading outputs, calibrated against humans.
- Indirect prompt injection: instructions hidden in content the model reads.
211G
Key ideas
- Minimal, non-root, digest-pinned, scanned, signed images with SBOMs.
- Kubernetes: zone spread, startup/readiness/liveness used correctly, graceful shutdown, requests from measurements, PDBs, NetworkPolicies, workload identity, external secrets.
- Everything in Terraform/OpenTofu; plans on PRs, applies from the pipeline, drift detection, policy checks, tags.
- IAM: SSO and short sessions for humans, workload identity for pods, OIDC for CI, audit logs.
- Private subnets for data; egress allow-lists; no bastion keys.
- CDN: immutable hashed assets, revalidated HTML,
stale-if-error for public APIs, never personalised data.
- TLS: automatic renewal, independent expiry monitoring, TLS 1.3, ECDSA, keep-alive and resumption.
- Pipeline: build once, sign, promote the digest, admission verifies signatures; GitOps; canary with automated analysis; rollback by digest; roll forward schemas.
Numbers to remember
- Lab: cached edge sent 895 of 20,000 requests to the origin; stale content served during an outage.
- HTTPS keep-alive ~110k/s vs new handshake per request ~1.9–2.3k/s; RSA-2048 sign 3.6k/s vs ECDSA P-256 52.6k/s.
Pitfalls
- Dependency-checking liveness probes; CPU throttling; static keys; caching personalised data; per-environment builds; hurried schema rollbacks.
Glossary
- PDB: PodDisruptionBudget.
- Workload identity: short-lived cloud credentials bound to a Kubernetes ServiceAccount.
- Admission controller: cluster component that can reject workloads (e.g. unsigned images).
- stale-if-error: serve expired cached content when the origin fails.
- cosign: Sigstore tool to sign and verify container images.
211H
Key ideas
- OpenTelemetry everywhere via a Collector; context through HTTP and Kafka; resource attributes.
- Logs with trace IDs; RED/USE/business metrics with low cardinality; tail-sampled traces; exemplars.
- Dashboards per journey; SLOs; burn-rate pages and tickets; runbooks; error-budget policy; canary analysis and synthetic checks on the same SLIs.
- OIDC with PKCE via a BFF; MFA for staff; roles for actions, object checks for data; approvals for high-risk actions.
- Secrets in a manager, rotated, scanned for.
- STRIDE threat model of the data-flow diagram, reviewed per milestone.
- Scanning, lockfiles, SBOMs, signatures and provenance; hardened CI.
- Audit logs: transactional, append-only, hash-chained, anchored.
Numbers to remember
- Lab: 5% canary — doubled error rate caught in ~3 min; +20% relative in ~47 min (86% of runs); false failures 3.4% with per-minute checks.
- Burn-rate pages: 14.4× (1 h/5 min), 6× (6 h/30 min); tickets 3× (1 d/2 h), 1× (3 d/6 h).
Pitfalls
- SLO-less dashboards; runbook-less alerts; cardinality explosions; RBAC without object checks; secrets in env files; rewritable audit logs.
Glossary
- Tail sampling: deciding which traces to keep after seeing them whole.
- Exemplar: a trace ID attached to a metric sample.
- Synthetic check: a scripted journey run from outside on a schedule.
- Provenance: signed metadata on how and from what an artefact was built.
- Anchor: a copy of the latest audit hash kept outside the log's control.
212A
Key ideas
- For every failure: detect, mitigate, recover, prevent.
- Exercises need a hypothesis, blast-radius limits, abort conditions and normal telemetry; automate the passing ones.
- Database outage: fail fast and reconnect fast; HA standby; failover drills.
- Cache outage: explicit timeouts, retries off, tested fallback, database capacity.
- Kafka outage: the outbox holds events; watch outbox age; throttle catch-up.
- Slow dependency: timeouts, bulkheads, breakers.
- CPU: find the knee; scale and shed before it.
- Memory: watch the slope; OOM kills are silent.
- Disk: logs off the node and off data volumes.
- Pod crash: replicas, PDBs, idempotency keys.
- Region loss: written criteria, cross-region data, rebuildable infrastructure, timed drills.
- Spikes: rate limits and admission control prepared in advance.
Numbers to remember
- DB outage: default pool → ~6 s waits and a backlog; 0.5 s timeout → fast failures, 3–4 s reconnection lag.
- Cache outage: default client retries 4.4 s per call → 1,424/6,000 failed; retries off → 0.
- Knee ~1,000–1,500 req/s; shedding kept p99 at 119 ms vs 3.3 s.
- Worker kill: GET 0 failures, POST 20.
- OOM: exit 137, no last log line.
Pitfalls
- Only clean failures tested; library defaults; untested fallbacks; no abort conditions; actions without owners.
Glossary
- Game day: a planned failure exercise with the team watching.
- Blast radius: how much can be affected by an experiment or failure.
- Load shedding: rejecting excess work early to protect accepted work.
- Knee: the load beyond which latency rises sharply.
- Exit code 137: process killed by SIGKILL (128 + 9), typical of OOM kills.
212B
Key ideas
- These failures look like success: no crash, wrong outcome.
- Duplicates: idempotent consumers; idempotency keys stored with results; reconciliation.
- Deployments: expand/contract for schemas, APIs and events; contract tests across versions.
- Migrations: transactional where possible; check data assumptions first; clean up invalid indexes; lock timeouts.
- Credentials and certificates: short-lived and automatic, with independent expiry monitoring.
- AI: timeouts, fallbacks and breakers; validate output; enforce tool policy in code; sandbox and limit document parsing.
Numbers to remember
- 3 concurrent copies × 200 payments: 600 charges without keys, 200 with.
- One-step rename: 757/757 old-version writes failed; expand/contract: 0.
- AI outage: 0/100 without timeout; 100/100 at median 1.3 s with breaker.
- Zip bomb: 1 MB → 1 GiB, ratio 1,029:1.
- curl exit 60 for an expired certificate.
Pitfalls
- "No errors" as "correct"; breaking changes in one release; unmonitored renewal; untested fallbacks; prompt-only security.
Glossary
- Expand/contract: changing a schema through compatible intermediate states.
- Reconciliation: comparing records between systems to find mismatches.
- INVALID index: a failed concurrent index build left in place.
- Certificate transparency: public logs of issued certificates you can monitor for your domains.
- Decompression ratio: uncompressed size divided by compressed size.