Microservices & Advanced Architecture
This chapter aligns service boundaries with domains, compares synchronous and asynchronous contracts, introduces mesh behavior and event-sourced projections, and applies the patterns to five large-scale products.
- Explain Service decomposition & communication by naming its input, guarantee, internal lifecycle, important failure, and proof.
- Explain Service mesh & event sourcing by naming its input, guarantee, internal lifecycle, important failure, and proof.
- Explain 5 advanced system designs by naming its input, guarantee, internal lifecycle, important failure, and proof.
- Explain Communication details by naming its input, guarantee, internal lifecycle, important failure, and proof.
- Trace the chapter's complete execution path and identify where memory, I/O, concurrency, persistence, or rendering cost accumulates.
How to use this chapter
For Microservices & Advanced Architecture, read the explanations first and predict every example before running it. Keep a learning repository containing code, tests, command output, and the short written submission. The roadmap checklist at the end audits coverage; the chapter itself follows the architecture learning arc appropriate to this subject.
The problem this chapter solves
This chapter aligns service boundaries with domains, compares synchronous and asynchronous contracts, introduces mesh behavior and event-sourced projections, and applies the patterns to five large-scale products.
Distributed systems fail partially and operate under finite latency, throughput, cost, and team capacity. Explicit trade-offs prevent accidental architectures.
Learning outcomes
- Explain Service decomposition & communication by naming its input, guarantee, internal lifecycle, important failure, and proof.
- Explain Service mesh & event sourcing by naming its input, guarantee, internal lifecycle, important failure, and proof.
- Explain 5 advanced system designs by naming its input, guarantee, internal lifecycle, important failure, and proof.
- Explain Communication details by naming its input, guarantee, internal lifecycle, important failure, and proof.
- Trace the chapter's complete execution path and identify where memory, I/O, concurrency, persistence, or rendering cost accumulates.
- Build the worked example, make one failure visible, and defend the design in a review.
Chapter progression
The order below is intentional: later sections depend on guarantees established earlier.
Runtime or system overview
Every remote call crosses a failure boundary. Replication creates ordering and consistency questions; queues separate production from consumption; caches create invalidation questions; partitioning creates routing and hotspot questions. Good designs make ownership and retry semantics visible. In Microservices & Advanced Architecture, use that execution model to decide where the chapter's validation, state ownership, cleanup, and evidence belong.
Execution trace
- The caller validates the request and attaches a stable operation identity.
- The owning service applies the authoritative invariant and commits durable state before advertising success.
- An outbox or versioned response communicates the result across process boundaries under explicit ordering and retry semantics.
- Downstream consumers update derived state idempotently and reconcile gaps or duplicates.
- Load, failure, security, and recovery tests verify the SLO and every critical state transition.
Memory and performance lens
Capacity planning considers working sets, cache hit rate, queue backlog, connection pools, fan-out, and per-request amplification. A small per-request allocation or extra query becomes material at high concurrency. For Microservices & Advanced Architecture, connect those costs to the concrete operations in the topic sections rather than assuming the friendly surface syntax is cheap.
When tuning Microservices & Advanced Architecture, measure capacity per critical path, tail latency, availability/error budget, consistency lag, recovery objectives, cost per outcome, and evaluation quality rather than optimizing from source-code appearance.
1. Service decomposition & communication
The Service decomposition & communication unit begins with DDD: bounded contexts/aggregates/entities: Domain-driven service decomposition assigns a bounded context, aggregate invariants, data ownership, and explicit synchronous or asynchronous contracts to each independently changeable service. Split by business capability, keep authoritative writes with their invariants, evolve schemas compatibly, and migrate monolith capabilities incrementally with a strangler path. The rest of this section connects that guarantee to this unit's related roadmap concepts instead of treating each term as an isolated flashcard.
Requirements, ownership, and trade-offs: Service decomposition & communication
| Concept | Meaning | Engineering decision |
|---|---|---|
| DDD: bounded contexts/aggregates/entities | Domain-driven service decomposition assigns a bounded context, aggregate invariants, data ownership, and explicit synchronous or asynchronous contracts to each independently changeable service. | Split by business capability, keep authoritative writes with their invariants, evolve schemas compatibly, and migrate monolith capabilities incrementally with a strangler path. |
| strangler fig pattern for monolith migration | Domain-driven service decomposition assigns a bounded context, aggregate invariants, data ownership, and explicit synchronous or asynchronous contracts to each independently changeable service. | Split by business capability, keep authoritative writes with their invariants, evolve schemas compatibly, and migrate monolith capabilities incrementally with a strangler path. |
| database-per-service + data consistency challenges | Domain-driven service decomposition assigns a bounded context, aggregate invariants, data ownership, and explicit synchronous or asynchronous contracts to each independently changeable service. | Split by business capability, keep authoritative writes with their invariants, evolve schemas compatibly, and migrate monolith capabilities incrementally with a strangler path. |
| REST vs gRPC (protobuf, all streaming types) vs GraphQL | Domain-driven service decomposition assigns a bounded context, aggregate invariants, data ownership, and explicit synchronous or asynchronous contracts to each independently changeable service. | Split by business capability, keep authoritative writes with their invariants, evolve schemas compatibly, and migrate monolith capabilities incrementally with a strangler path. |
| async via Kafka + service discovery | Domain-driven service decomposition assigns a bounded context, aggregate invariants, data ownership, and explicit synchronous or asynchronous contracts to each independently changeable service. | Split by business capability, keep authoritative writes with their invariants, evolve schemas compatibly, and migrate monolith capabilities incrementally with a strangler path. |
Critical path and failure behavior: Service decomposition & communication
DDD: bounded contexts/aggregates/entities. REST and gRPC couple caller latency to a callee; streams add backpressure and lifecycle; Kafka decouples time but introduces schema, ordering, replay, and duplicate-delivery concerns; discovery maps logical service identities to healthy endpoints.
strangler fig pattern for monolith migration. REST and gRPC couple caller latency to a callee; streams add backpressure and lifecycle; Kafka decouples time but introduces schema, ordering, replay, and duplicate-delivery concerns; discovery maps logical service identities to healthy endpoints.
database-per-service + data consistency challenges. REST and gRPC couple caller latency to a callee; streams add backpressure and lifecycle; Kafka decouples time but introduces schema, ordering, replay, and duplicate-delivery concerns; discovery maps logical service identities to healthy endpoints.
REST vs gRPC (protobuf, all streaming types) vs GraphQL. REST and gRPC couple caller latency to a callee; streams add backpressure and lifecycle; Kafka decouples time but introduces schema, ordering, replay, and duplicate-delivery concerns; discovery maps logical service identities to healthy endpoints.
async via Kafka + service discovery. REST and gRPC couple caller latency to a callee; streams add backpressure and lifecycle; Kafka decouples time but introduces schema, ordering, replay, and duplicate-delivery concerns; discovery maps logical service identities to healthy endpoints.
Read these as one system: DDD: bounded contexts/aggregates/entities establishes the starting contract, strangler fig pattern for monolith migration changes how that contract is executed or represented, and async via Kafka + service discovery exposes a later boundary or failure condition. A local optimization is useful only when the combined behavior stays correct and observable.
A concrete design decision: Service decomposition & communication
1type Query { recipe(id: ID!): Recipe }2type Recipe { id: ID!, title: String!, reviews(first: Int!): ReviewConnection! }This Service decomposition & communication slice makes DDD: bounded contexts/aggregates/entities observable. Read it from the boundary inward: identify the input, the validation point, the state or operation, and the value that proves the result. Before extending it toward async via Kafka + service discovery, predict its behavior for empty, invalid, repeated, and large input.
Designs that fail under real load: Service decomposition & communication
| Risk | Why it matters |
|---|---|
| DDD: bounded contexts/aggregates/entities | A bounded context is not GraphQL context, database-per-service is not React Server Component composition, and gRPC streaming is not an LLM response stream. |
| strangler fig pattern for monolith migration | A bounded context is not GraphQL context, database-per-service is not React Server Component composition, and gRPC streaming is not an LLM response stream. |
| database-per-service + data consistency challenges | A bounded context is not GraphQL context, database-per-service is not React Server Component composition, and gRPC streaming is not an LLM response stream. |
| REST vs gRPC (protobuf, all streaming types) vs GraphQL | A bounded context is not GraphQL context, database-per-service is not React Server Component composition, and gRPC streaming is not an LLM response stream. |
| async via Kafka + service discovery | A bounded context is not GraphQL context, database-per-service is not React Server Component composition, and gRPC streaming is not an LLM response stream. |
Design review exercise: Service decomposition & communication
- Foundation: implement or demonstrate DDD: bounded contexts/aggregates/entities with one valid input and one invalid input. Record the exact output or failure.
- Integration: combine DDD: bounded contexts/aggregates/entities with strangler fig pattern for monolith migration. Explain which component owns validation and cleanup.
- Production: design a test or experiment that exposes the failure described for async via Kafka + service discovery. State the metric, assertion, or query plan that proves the correction.
What a strong checkpoint answer contains
- A precise boundary and typed or validated input.
- One named guarantee, not only a library call.
- A negative case that fails for the intended reason.
- Cleanup, transaction, retry, or cancellation behavior where applicable.
- Evidence: assertion, command output, plan, trace, metric, or accessible UI state.
2. Service mesh & event sourcing
The Service mesh & event sourcing unit begins with Istio: Envoy sidecar, mTLS between services: A service mesh applies identity, encryption, telemetry, routing, and resilience at the transport layer, while event sourcing records domain changes and derives projections for reads. Keep business retries and idempotency in application contracts, version events, make projection rebuilds repeatable, and measure mesh overhead. The rest of this section connects that guarantee to this unit's related roadmap concepts instead of treating each term as an isolated flashcard.
Requirements, ownership, and trade-offs: Service mesh & event sourcing
| Concept | Meaning | Engineering decision |
|---|---|---|
| Istio: Envoy sidecar, mTLS between services | A service mesh applies identity, encryption, telemetry, routing, and resilience at the transport layer, while event sourcing records domain changes and derives projections for reads. | Keep business retries and idempotency in application contracts, version events, make projection rebuilds repeatable, and measure mesh overhead. |
| traffic management: canary/circuit breaker/retries | A service mesh applies identity, encryption, telemetry, routing, and resilience at the transport layer, while event sourcing records domain changes and derives projections for reads. | Keep business retries and idempotency in application contracts, version events, make projection rebuilds repeatable, and measure mesh overhead. |
| event store design + projections (read models) | A service mesh applies identity, encryption, telemetry, routing, and resilience at the transport layer, while event sourcing records domain changes and derives projections for reads. | Keep business retries and idempotency in application contracts, version events, make projection rebuilds repeatable, and measure mesh overhead. |
| snapshots for long event histories | A service mesh applies identity, encryption, telemetry, routing, and resilience at the transport layer, while event sourcing records domain changes and derives projections for reads. | Keep business retries and idempotency in application contracts, version events, make projection rebuilds repeatable, and measure mesh overhead. |
Critical path and failure behavior: Service mesh & event sourcing
Istio: Envoy sidecar, mTLS between services. Envoy sidecars intercept traffic under mesh policy; mTLS authenticates workloads; canary routes shift traffic; an append-only event store rebuilds projections and snapshots shorten replay without replacing history.
traffic management: canary/circuit breaker/retries. Envoy sidecars intercept traffic under mesh policy; mTLS authenticates workloads; canary routes shift traffic; an append-only event store rebuilds projections and snapshots shorten replay without replacing history.
event store design + projections (read models). Envoy sidecars intercept traffic under mesh policy; mTLS authenticates workloads; canary routes shift traffic; an append-only event store rebuilds projections and snapshots shorten replay without replacing history.
snapshots for long event histories. Envoy sidecars intercept traffic under mesh policy; mTLS authenticates workloads; canary routes shift traffic; an append-only event store rebuilds projections and snapshots shorten replay without replacing history.
Read these as one system: Istio: Envoy sidecar, mTLS between services establishes the starting contract, traffic management: canary/circuit breaker/retries changes how that contract is executed or represented, and snapshots for long event histories exposes a later boundary or failure condition. A local optimization is useful only when the combined behavior stays correct and observable.
Designs that fail under real load: Service mesh & event sourcing
| Risk | Why it matters |
|---|---|
| Istio: Envoy sidecar, mTLS between services | mTLS is not Kubernetes ingress TLS, automatic retries can duplicate side effects, and a snapshot without later events is not authoritative state. |
| traffic management: canary/circuit breaker/retries | mTLS is not Kubernetes ingress TLS, automatic retries can duplicate side effects, and a snapshot without later events is not authoritative state. |
| event store design + projections (read models) | mTLS is not Kubernetes ingress TLS, automatic retries can duplicate side effects, and a snapshot without later events is not authoritative state. |
| snapshots for long event histories | mTLS is not Kubernetes ingress TLS, automatic retries can duplicate side effects, and a snapshot without later events is not authoritative state. |
Design review exercise: Service mesh & event sourcing
- Foundation: implement or demonstrate Istio: Envoy sidecar, mTLS between services with one valid input and one invalid input. Record the exact output or failure.
- Integration: combine Istio: Envoy sidecar, mTLS between services with traffic management: canary/circuit breaker/retries. Explain which component owns validation and cleanup.
- Production: design a test or experiment that exposes the failure described for snapshots for long event histories. State the metric, assertion, or query plan that proves the correction.
What a strong checkpoint answer contains
- A precise boundary and typed or validated input.
- One named guarantee, not only a library call.
- A negative case that fails for the intended reason.
- Cleanup, transaction, retry, or cancellation behavior where applicable.
- Evidence: assertion, command output, plan, trace, metric, or accessible UI state.
3. 5 advanced system designs
The 5 advanced system designs unit begins with Instagram: media upload/feed generation/follow graph: Advanced product designs combine workload-specific storage, partitioning, fan-out, media pipelines, geospatial or prefix indexes, and graceful degradation rather than relying on one universal architecture. Estimate skew and bandwidth, identify authoritative state, define hot-key handling, and explain regional failure and recovery paths. The rest of this section connects that guarantee to this unit's related roadmap concepts instead of treating each term as an isolated flashcard.
Requirements, ownership, and trade-offs: 5 advanced system designs
| Concept | Meaning | Engineering decision |
|---|---|---|
| Instagram: media upload/feed generation/follow graph | Advanced product designs combine workload-specific storage, partitioning, fan-out, media pipelines, geospatial or prefix indexes, and graceful degradation rather than relying on one universal architecture. | Estimate skew and bandwidth, identify authoritative state, define hot-key handling, and explain regional failure and recovery paths. |
| Uber: real-time location/matching/surge pricing | Advanced product designs combine workload-specific storage, partitioning, fan-out, media pipelines, geospatial or prefix indexes, and graceful degradation rather than relying on one universal architecture. | Estimate skew and bandwidth, identify authoritative state, define hot-key handling, and explain regional failure and recovery paths. |
| YouTube: upload pipeline/transcoding/streaming | Advanced product designs combine workload-specific storage, partitioning, fan-out, media pipelines, geospatial or prefix indexes, and graceful degradation rather than relying on one universal architecture. | Estimate skew and bandwidth, identify authoritative state, define hot-key handling, and explain regional failure and recovery paths. |
| Distributed Cache (Redis-like from scratch) | Advanced product designs combine workload-specific storage, partitioning, fan-out, media pipelines, geospatial or prefix indexes, and graceful degradation rather than relying on one universal architecture. | Estimate skew and bandwidth, identify authoritative state, define hot-key handling, and explain regional failure and recovery paths. |
| Search autocomplete (trie/prefix tree at scale) | Advanced product designs combine workload-specific storage, partitioning, fan-out, media pipelines, geospatial or prefix indexes, and graceful degradation rather than relying on one universal architecture. | Estimate skew and bandwidth, identify authoritative state, define hot-key handling, and explain regional failure and recovery paths. |
Critical path and failure behavior: 5 advanced system designs
Instagram: media upload/feed generation/follow graph. Each design narrows expensive work: feed systems choose push/pull by follower skew, media services transcode immutable renditions, location services search nearby cells, distributed caches map keys to owners, and autocomplete traverses compact prefix structures.
Uber: real-time location/matching/surge pricing. Each design narrows expensive work: feed systems choose push/pull by follower skew, media services transcode immutable renditions, location services search nearby cells, distributed caches map keys to owners, and autocomplete traverses compact prefix structures.
YouTube: upload pipeline/transcoding/streaming. Each design narrows expensive work: feed systems choose push/pull by follower skew, media services transcode immutable renditions, location services search nearby cells, distributed caches map keys to owners, and autocomplete traverses compact prefix structures.
Distributed Cache (Redis-like from scratch). Each design narrows expensive work: feed systems choose push/pull by follower skew, media services transcode immutable renditions, location services search nearby cells, distributed caches map keys to owners, and autocomplete traverses compact prefix structures.
Search autocomplete (trie/prefix tree at scale). Each design narrows expensive work: feed systems choose push/pull by follower skew, media services transcode immutable renditions, location services search nearby cells, distributed caches map keys to owners, and autocomplete traverses compact prefix structures.
Read these as one system: Instagram: media upload/feed generation/follow graph establishes the starting contract, Uber: real-time location/matching/surge pricing changes how that contract is executed or represented, and Search autocomplete (trie/prefix tree at scale) exposes a later boundary or failure condition. A local optimization is useful only when the combined behavior stays correct and observable.
Designs that fail under real load: 5 advanced system designs
| Risk | Why it matters |
|---|---|
| Instagram: media upload/feed generation/follow graph | YouTube streaming is media delivery rather than an LLM stream; average throughput hides celebrity, viral, and geographic hotspots. |
| Uber: real-time location/matching/surge pricing | YouTube streaming is media delivery rather than an LLM stream; average throughput hides celebrity, viral, and geographic hotspots. |
| YouTube: upload pipeline/transcoding/streaming | YouTube streaming is media delivery rather than an LLM stream; average throughput hides celebrity, viral, and geographic hotspots. |
| Distributed Cache (Redis-like from scratch) | YouTube streaming is media delivery rather than an LLM stream; average throughput hides celebrity, viral, and geographic hotspots. |
| Search autocomplete (trie/prefix tree at scale) | YouTube streaming is media delivery rather than an LLM stream; average throughput hides celebrity, viral, and geographic hotspots. |
Design review exercise: 5 advanced system designs
- Foundation: implement or demonstrate Instagram: media upload/feed generation/follow graph with one valid input and one invalid input. Record the exact output or failure.
- Integration: combine Instagram: media upload/feed generation/follow graph with Uber: real-time location/matching/surge pricing. Explain which component owns validation and cleanup.
- Production: design a test or experiment that exposes the failure described for Search autocomplete (trie/prefix tree at scale). State the metric, assertion, or query plan that proves the correction.
What a strong checkpoint answer contains
- A precise boundary and typed or validated input.
- One named guarantee, not only a library call.
- A negative case that fails for the intended reason.
- Cleanup, transaction, retry, or cancellation behavior where applicable.
- Evidence: assertion, command output, plan, trace, metric, or accessible UI state.
4. Communication details
The Communication details unit begins with gRPC unary/client-stream/server-stream/bidirectional-stream: gRPC supports unary, client-streaming, server-streaming, and bidirectional-streaming RPCs over HTTP/2; asynchronous request-reply uses messages plus a correlation identity and deadline instead of holding a socket. Use unary by default, stream only when incremental delivery/backpressure matters, and reserve field numbers through compatible schema evolution. The rest of this section connects that guarantee to this unit's related roadmap concepts instead of treating each term as an isolated flashcard.
Requirements, ownership, and trade-offs: Communication details
| Concept | Meaning | Engineering decision |
|---|---|---|
| gRPC unary/client-stream/server-stream/bidirectional-stream | gRPC supports unary, client-streaming, server-streaming, and bidirectional-streaming RPCs over HTTP/2; asynchronous request-reply uses messages plus a correlation identity and deadline instead of holding a socket. | Use unary by default, stream only when incremental delivery/backpressure matters, and reserve field numbers through compatible schema evolution. |
| async request-reply with correlation ID and timeout | gRPC supports unary, client-streaming, server-streaming, and bidirectional-streaming RPCs over HTTP/2; asynchronous request-reply uses messages plus a correlation identity and deadline instead of holding a socket. | Use unary by default, stream only when incremental delivery/backpressure matters, and reserve field numbers through compatible schema evolution. |
| schema/version compatibility across services | gRPC supports unary, client-streaming, server-streaming, and bidirectional-streaming RPCs over HTTP/2; asynchronous request-reply uses messages plus a correlation identity and deadline instead of holding a socket. | Use unary by default, stream only when incremental delivery/backpressure matters, and reserve field numbers through compatible schema evolution. |
| service discovery health and stale endpoint handling | A service boundary owns a cohesive domain model and data, while communication contracts expose only what other contexts need. | Split by business ownership and independent change, not by technical layer. |
Critical path and failure behavior: Communication details
gRPC unary/client-stream/server-stream/bidirectional-stream. Generated protobuf types encode numbered fields; deadlines and cancellation propagate through RPC context. Async replies route by correlation ID and may arrive after the requester timed out.
async request-reply with correlation ID and timeout. Generated protobuf types encode numbered fields; deadlines and cancellation propagate through RPC context. Async replies route by correlation ID and may arrive after the requester timed out.
schema/version compatibility across services. Generated protobuf types encode numbered fields; deadlines and cancellation propagate through RPC context. Async replies route by correlation ID and may arrive after the requester timed out.
service discovery health and stale endpoint handling. Synchronous calls couple availability and latency; events couple schemas and ordering; discovery maps logical names to healthy instances. Strangler migration diverts one capability at a time from a monolith.
Read these as one system: gRPC unary/client-stream/server-stream/bidirectional-stream establishes the starting contract, async request-reply with correlation ID and timeout changes how that contract is executed or represented, and service discovery health and stale endpoint handling exposes a later boundary or failure condition. A local optimization is useful only when the combined behavior stays correct and observable.
Designs that fail under real load: Communication details
| Risk | Why it matters |
|---|---|
| gRPC unary/client-stream/server-stream/bidirectional-stream | Streaming increases lifecycle complexity, and retrying an RPC without idempotency can duplicate side effects. |
| async request-reply with correlation ID and timeout | Streaming increases lifecycle complexity, and retrying an RPC without idempotency can duplicate side effects. |
| schema/version compatibility across services | Streaming increases lifecycle complexity, and retrying an RPC without idempotency can duplicate side effects. |
| service discovery health and stale endpoint handling | A shared database preserves hidden coupling and distributed chatty calls create a network monolith. |
Design review exercise: Communication details
- Foundation: implement or demonstrate gRPC unary/client-stream/server-stream/bidirectional-stream with one valid input and one invalid input. Record the exact output or failure.
- Integration: combine gRPC unary/client-stream/server-stream/bidirectional-stream with async request-reply with correlation ID and timeout. Explain which component owns validation and cleanup.
- Production: design a test or experiment that exposes the failure described for service discovery health and stale endpoint handling. State the metric, assertion, or query plan that proves the correction.
What a strong checkpoint answer contains
- A precise boundary and typed or validated input.
- One named guarantee, not only a library call.
- A negative case that fails for the intended reason.
- Cleanup, transaction, retry, or cancellation behavior where applicable.
- Evidence: assertion, command output, plan, trace, metric, or accessible UI state.
Complete worked example
This example integrates the chapter rather than demonstrating an isolated method.
1syntax = "proto3";2package profile.v1;3
4service ProfileService {5 rpc GetProfile(GetProfileRequest) returns (Profile);6 rpc WatchPresence(WatchPresenceRequest) returns (stream PresenceEvent);7}8
9message GetProfileRequest { string user_id = 1; }10message Profile { string user_id = 1; string display_name = 2; uint64 version = 3; }11message WatchPresenceRequest { repeated string user_ids = 1; }12message PresenceEvent { string user_id = 1; string state = 2; int64 observed_at_ms = 3; }Expected result
1A unary read and server-streaming presence contract are versioned independently of storage models.Line-by-line reading
| Line | Code | Explanation |
|---|---|---|
| 1 | syntax = "proto3"; | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 2 | package profile.v1; | Implements the next protobuf statement in the example's data flow. |
| 4 | service ProfileService { | Implements the next protobuf statement in the example's data flow. |
| 5 | rpc GetProfile(GetProfileRequest) returns (Profile); | Implements the next protobuf statement in the example's data flow. |
| 6 | rpc WatchPresence(WatchPresenceRequest) returns (stream PresenceEvent); | Implements the next protobuf statement in the example's data flow. |
| 7 | } | Implements the next protobuf statement in the example's data flow. |
| 9 | message GetProfileRequest { string user_id = 1; } | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 10 | message Profile { string user_id = 1; string display_name = 2; uint64 version = 3; } | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 11 | message WatchPresenceRequest { repeated string user_ids = 1; } | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 12 | message PresenceEvent { string user_id = 1; string state = 2; int64 observed_at_ms = 3; } | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
Step-by-step execution
- The caller validates the request and attaches a stable operation identity.
- The owning service applies the authoritative invariant and commits durable state before advertising success.
- An outbox or versioned response communicates the result across process boundaries under explicit ordering and retry semantics.
- Downstream consumers update derived state idempotently and reconcile gaps or duplicates.
- Load, failure, security, and recovery tests verify the SLO and every critical state transition.
Common mistakes and professional corrections
| Area | Common failure | Better engineering choice |
|---|---|---|
| Service decomposition & communication | A bounded context is not GraphQL context, database-per-service is not React Server Component composition, and gRPC streaming is not an LLM response stream. | Split by business capability, keep authoritative writes with their invariants, evolve schemas compatibly, and migrate monolith capabilities incrementally with a strangler path. |
| Service mesh & event sourcing | mTLS is not Kubernetes ingress TLS, automatic retries can duplicate side effects, and a snapshot without later events is not authoritative state. | Keep business retries and idempotency in application contracts, version events, make projection rebuilds repeatable, and measure mesh overhead. |
| 5 advanced system designs | YouTube streaming is media delivery rather than an LLM stream; average throughput hides celebrity, viral, and geographic hotspots. | Estimate skew and bandwidth, identify authoritative state, define hot-key handling, and explain regional failure and recovery paths. |
| Communication details | Streaming increases lifecycle complexity, and retrying an RPC without idempotency can duplicate side effects. | Use unary by default, stream only when incremental delivery/backpressure matters, and reserve field numbers through compatible schema evolution. |
Interview and review notes
- Define the central abstraction without naming a library function.
- Trace one request, call, query, message, render, or state transition from input to observable result.
- Compare two alternatives from this chapter by guarantee, cost, and failure behavior.
- Explain the most likely production bug and the test or metric that reveals it.
- State what remains authoritative after process loss, retry, reconnect, or deployment.
Practice set
Easy
- Define every bold term in the concept tables in one precise sentence.
- Reproduce the focused examples and annotate the value or state after each important line.
- Explain the chapter progression diagram aloud in two minutes.
Medium
- Replace one convenient default with an explicit policy for validation, timeout, ordering, pagination, cleanup, or error handling.
- Write a negative test for each topic group.
- Compare the measured behavior before and after one justified change.
Hard
- Combine all topic groups into one thin vertical slice.
- Inject a realistic failure at the most important external boundary and prove recovery.
- Write a one-page design note covering ownership, trade-offs, security, observability, and rollback.
Chapter submission
Submit:
- source code or reproducible commands;
- automated tests plus one deliberately failing-before-fix test;
- captured output, query plan, trace, screenshot, or metric;
- a 300–500 word explanation of the execution flow and one rejected alternative;
- a short README with setup, versions, limitations, and cleanup steps.
- Continue with the Advanced System Designs Doc project workshop.
Self-review rubric
| Dimension | Beginning | Competent | Professional |
|---|---|---|---|
| Explanation | Names APIs | Explains behavior | Connects guarantees, internals, and trade-offs |
| Implementation | Happy path only | Validated and tested | Clear ownership, failure recovery, and cleanup |
| Evidence | Manual claim | Repeatable output | Tests plus meaningful measurement or inspection |
| Communication | Steps missing | Reproducible README | Decisions, limits, and alternatives are explicit |
Roadmap coverage checklist
- To do: Service decomposition & communication: DDD: bounded contexts/aggregates/entities
- To do: Service decomposition & communication: strangler fig pattern for monolith migration
- To do: Service decomposition & communication: database-per-service + data consistency challenges
- To do: Service decomposition & communication: REST vs gRPC (protobuf, all streaming types) vs GraphQL
- To do: Service decomposition & communication: async via Kafka + service discovery
- To do: Service mesh & event sourcing: Istio: Envoy sidecar, mTLS between services
- To do: Service mesh & event sourcing: traffic management: canary/circuit breaker/retries
- To do: Service mesh & event sourcing: event store design + projections (read models)
- To do: Service mesh & event sourcing: snapshots for long event histories
- To do: 5 advanced system designs: Instagram: media upload/feed generation/follow graph
- To do: 5 advanced system designs: Uber: real-time location/matching/surge pricing
- To do: 5 advanced system designs: YouTube: upload pipeline/transcoding/streaming
- To do: 5 advanced system designs: Distributed Cache (Redis-like from scratch)
- To do: 5 advanced system designs: Search autocomplete (trie/prefix tree at scale)
- To do: Communication details: gRPC unary/client-stream/server-stream/bidirectional-stream
- To do: Communication details: async request-reply with correlation ID and timeout
- To do: Communication details: schema/version compatibility across services
- To do: Communication details: service discovery health and stale endpoint handling
Quick revision
- Service decomposition & communication: connect the surface API to its guarantee, lifecycle, failure boundary, and evidence.
- Service mesh & event sourcing: connect the surface API to its guarantee, lifecycle, failure boundary, and evidence.
- 5 advanced system designs: connect the surface API to its guarantee, lifecycle, failure boundary, and evidence.
- Communication details: connect the surface API to its guarantee, lifecycle, failure boundary, and evidence.
- Re-read the worked-example execution trace instead of memorizing isolated syntax.
- If you cannot name the owner of state and cleanup, the design is not yet complete.
Mastery check
How well can you recall this?
Finished this lesson?