System design, part 6 of 12
Architecture Styles
An architecture style is a decision about where the boundaries go: what deploys together, who owns which data, and how the pieces talk. This page compares the main shapes, shows how to split a system and how the parts cooperate, covers the platform patterns an architect is expected to know, and ends with a way to choose and to defend the choice in an interview.
Shapes of a system
Part 1 of 5 · what deploys together
Four deployment shapes cover almost every system. They differ in how many things you deploy and who owns the data, not in how clean the code is. Code structure inside a deployable is a separate choice.
- The four shapes compared: one table
- The four shapes drawn: a small diagram each
- When microservices are worth it: and the distributed monolith
- Layered, hexagonal, clean: structure inside one deployable
The four shapes compared
Default to the simplest shape that the team and the load allow. Each step to the right buys independent deployment or scaling and pays for it in operations and in distributed-systems problems.
| Monolith | Modular monolith | Microservices | Serverless functions | |
|---|---|---|---|---|
| Team size it suits | 1 to about 10 engineers | About 10 to 50, several teams in one repo | Many teams (roughly 50+ engineers) that block each other on releases | Any size, for event-driven or spiky workloads |
| Deployment | One artifact, one pipeline | One artifact, modules with enforced boundaries | One pipeline per service, independent releases | Per function, platform runs it |
| Scaling | Clone the whole app behind a load balancer | Same; hot modules can be extracted later | Each service scales on its own curve | Automatic, per request, to zero when idle |
| Data ownership | One shared schema | One database, a schema per module, no cross-module joins | A database per service | External managed stores; functions are stateless |
| Operational cost | Lowest | Low | High: tracing, service discovery, per-service on-call, platform team | Low to run, pay per call; expensive at steady high volume |
| Calls between parts | In-process, nanoseconds, transactional | In-process through module interfaces | Network: about 0.5 to 2 ms each inside a data centre, can fail | Network plus events |
| Failure modes | One bug or memory leak takes everything down; slow builds; merge contention | Same blast radius as a monolith; boundaries erode without tooling | Partial failure, cascading timeouts, inconsistent data, version skew | Cold starts (roughly 100 ms to seconds), time limits, connection exhaustion on databases, vendor lock-in |
Senior signal: say which shape you start with and why, then name the measurable trigger that would move you to the next one. "Microservices" stated as a default with no trigger reads as mid-level.
The four shapes drawn
Monolith
Modular monolith
Microservices
Serverless functions
When microservices are worth it
Microservices solve an organisational problem (many teams shipping independently) more often than a technical one. Split when at least one of these is true and measurable:
- Release contention: teams wait on each other to deploy, or one team's bug rolls back everyone's release.
- Divergent scaling: one component needs 50 times the capacity, or GPUs, or a different memory profile.
- Divergent availability or compliance: payments needs 99.99% and PCI scope; the recommendations widget does not.
- Fault isolation: a leak in report generation must not take down checkout.
- Different technology: a component is genuinely better served by another runtime or data store.
Stay with a (modular) monolith when the domain is still being discovered, the team is small, or you cannot yet afford the platform: automated deployment, centralised logs, tracing and on-call per service.
The distributed monolith
The worst of both: separate deployables that still must be released, scaled or debugged together.
| Symptom | Root cause |
|---|---|
| A feature needs coordinated deploys of 3+ services | Boundaries cut through a business capability |
| Services read or write each other's tables | Shared database |
| One service down makes most requests fail | Long synchronous call chains, no fallbacks |
| Shared library upgrade forces a fleet-wide release | Domain logic in shared code instead of behind an API |
| Cannot run or test one service alone | No contracts; integration only testable end to end |
Interview tip: the test for a real service is "can it be deployed on a Tuesday afternoon without telling any other team?" If not, it is a module with a network cable through it.
Layered, hexagonal, clean
These describe structure inside one deployable and apply to a monolith or a single microservice alike. All three separate business rules from I/O; they differ in which way dependencies point.
| Layered (n-tier) | Hexagonal (ports and adapters) | Clean architecture | |
|---|---|---|---|
| Dependency rule | Each layer calls the one below | Adapters depend on the core; the core depends on nothing external | Same rule, with named rings: entities, use cases, interface adapters, frameworks |
| Core knows the database? | Yes, usually through an ORM | No, only an outbound port | No |
| Testing the rules | Needs a database or heavy mocking | Swap adapters for in-memory fakes | Same |
| Cost | Least code; fine for CRUD | More interfaces and mapping code | Most ceremony; several models to map between |
| Use when | Thin logic over a database | Real domain rules, several entry points or swappable infrastructure | Large, long-lived domain core with many use cases |
Hexagonal and clean are the same idea at different levels of prescription. For the code-level mechanics (dependency inversion, repository, adapter) see Design Principles and Design Patterns, and Low-Level Design.
Splitting a system
Part 2 of 5 · where the boundaries go
A good boundary keeps changes local: most features touch one service, and most requests are served from data the service already owns. Boundaries follow the business domain and the data, not the technical layers.
- Boundaries with domain-driven design: bounded context, aggregate, context map
- Database per service: why shared databases couple
- Ownership and duplication: one writer, many copies
- Migrating off a monolith: strangler fig, anti-corruption layer, branch by abstraction
- Conway's law
Boundaries with domain-driven design
Domain-driven design gives the vocabulary interviewers expect when you justify a service boundary.
| Term | Definition | E-commerce example |
|---|---|---|
| Ubiquitous language | One shared vocabulary used by the business and in the code, valid inside one context | "Order", "shipment", "refund" mean exactly one thing to the team that owns them |
| Bounded context | The boundary inside which a model and its language are consistent. The natural candidate for a service or module | "Product" in Catalog has description and images; in Inventory it is a SKU with a count; in Shipping it is weight and dimensions |
| Aggregate | A cluster of objects changed together in one transaction through a root; the unit of consistency. Other aggregates are referenced by id only | Order with its order lines. Customer and Product are referenced by id |
| Domain event | A fact that already happened, named in the past tense | OrderPlaced, PaymentCaptured, StockReserved |
| Context map | The relationships between contexts: who is upstream, who conforms, where translation happens | Ordering is downstream of Catalog and upstream of Shipping |
- Finding contexts: look for where the same word changes meaning, where a different team or business process takes over, and where data changes at a different rate.
- Aggregate rule: one transaction changes one aggregate. Anything across aggregates is eventually consistent (events, sagas). This is what makes a later split possible.
- Size: a service is one bounded context or a few closely related aggregates, not one entity. "User service, order service, product service" by table is an entity split and tends to produce chatty calls.
- Spend unevenly: build the core domain in-house, keep supporting contexts simple, buy generic ones.
Database per service
A service owns its data and exposes it only through its API or its events. "Database" means a private schema at minimum; it does not have to be a separate server.
Why a shared database couples services:
- Schema coupling: a column rename needs every reader changed and deployed together.
- Hidden contracts: other teams' queries depend on your tables, indexes and even row ordering.
- Runtime coupling: one team's slow query or lock exhausts connections for everyone; one capacity limit and one failure domain.
- No encapsulation: invariants enforced in service code are bypassed by direct writes.
Trade-off: you give up cross-service joins and ACID transactions. Joins become API composition or a local read copy; transactions become sagas (see Distributed Systems Patterns). If two "services" need a transaction together constantly, they are probably one service.
Ownership and duplication
Every piece of data has exactly one system of record that may write it. Everyone else holds a read-only copy or asks the owner.
| Need data from another service | How | Pay with |
|---|---|---|
| Rarely, must be fresh | Synchronous API call to the owner | Latency and availability coupling |
| Often, slightly stale is fine | Keep a local replica fed by the owner's events | Eventual consistency, storage, rebuild logic |
| As it was at a point in time | Copy the value into your own record (snapshot) | Nothing: this is correct, not denormalised. An order must keep the price and address at purchase time |
| For reporting across everything | Stream all services into a warehouse or lake | A pipeline to operate; minutes to hours of lag |
- Duplicate data, never duplicate ownership. A copy carries the owner's id and version so it can be refreshed or reconciled.
- Publish events reliably with the transactional outbox or change data capture, not a dual write (see Distributed Systems Patterns).
- Plan for rebuilds: a consumer must be able to rebuild its copy from a replay or a bulk export.
Migrating off a monolith
Never rewrite in one step. Put a routing layer in front, move one capability at a time, and keep the monolith serving the rest until nothing is left. This is the strangler fig pattern.
- Insert the facade (gateway or reverse proxy) with all routes still pointing at the monolith.
- Pick a capability with clear boundaries and real pain. Build it as a service with its own data store.
- Migrate the data: backfill, then keep in sync (change data capture or dual write with reconciliation), compare results in shadow mode.
- Shift traffic gradually; keep the old path as the rollback.
- Delete the old code and tables. A migration that skips this step leaves two systems forever.
| Technique | What it is | Use when |
|---|---|---|
| Strangler fig | Route at the edge; new system grows around the old one | The capability has its own entry points (URLs, topics) |
| Anti-corruption layer | A translation layer so the new model is not shaped by the legacy model (or a vendor's) | The new service must still call or be called by the old one |
| Branch by abstraction | Inside the codebase: introduce an interface, put old and new implementations behind it, switch with a flag, delete the old | The thing being replaced is deep inside the monolith with no external entry point |
| Parallel run | Call both, serve the old result, compare and log differences | Correctness is critical (pricing, billing) |
Failure mode: extracting the code but leaving the tables in the monolith database. The data migration is the hard half; say how you would do it.
Conway's law
Systems end up mirroring the communication structure of the organisation that builds them, so a service boundary that cuts across a team, or a team that spans many services, will be fought constantly. The practical use is the "inverse Conway manoeuvre": decide the architecture you want, then shape teams to match it, one team owning each service end to end.
How services cooperate
Part 3 of 5 · commands, events and read models
Once there are several services, the main design question is who knows about whom. Synchronous calls are simple and couple availability; events decouple and make the flow harder to see.
- Orchestration vs choreography
- Three kinds of event-driven: notification, state transfer, sourcing
- CQRS: separate read and write models
- Event sourcing: the log is the truth
- Sagas, gateways and meshes: where they are covered
- Sidecar, ambassador, adapter
Orchestration vs choreography
Use orchestration when the workflow has an order, compensation steps and a business owner who asks "where is order 42 stuck?". Use choreography for fan-out where the producer should not care who reacts.
| Orchestration | Choreography | |
|---|---|---|
| Flow lives in | One place (orchestrator or workflow engine) | Spread across subscribers |
| Coupling | Orchestrator knows every participant | Producer knows no consumers; consumers couple to event schemas |
| Adding a step | Change the orchestrator | Add a subscriber, no producer change |
| Visibility | Workflow state is queryable | Needs tracing and correlation ids to reconstruct |
| Failure handling | Explicit retries, timeouts, compensation in one place | Each service handles its own; cyclic event chains are possible |
| Risk | Orchestrator becomes a god service holding business logic | Nobody can say what happens after an event |
| Typical use | Checkout, onboarding, money movement | Notifications, analytics, search indexing, cache invalidation |
Interview tip: most real systems mix them: orchestrate the critical path (reserve, charge, confirm) and publish an event at the end for everything else to choreograph around. An orchestrator can also drive steps asynchronously through queues; orchestration is not the same thing as synchronous.
Three kinds of event-driven
"Event-driven" covers three different designs. Say which one you mean.
| Event notification | Event-carried state transfer | Event sourcing | |
|---|---|---|---|
| Event contains | An id and what happened: OrderPlaced {id: 42} | The full state needed by consumers: order lines, totals, address | Every state change of an entity, in order |
| Consumer then | Calls back to the producer for details | Updates its own local copy; no call back | Is usually the same service, rebuilding its own state |
| Scope | Between services | Between services | Inside one service: a persistence choice |
| Gain | Small events, loose schema coupling | Consumer works while the producer is down; fewer calls | Full audit trail, time travel, rebuildable read models |
| Pay | Call-back load on the producer; reads may see newer state than the event described | Larger events, duplicated data, schema becomes a public contract | Complexity: versioning, replay, eventual consistency |
- These are independent: you can publish integration events without event sourcing, and event-source one service without anyone outside knowing.
- Do not expose internal event-sourcing events as the public contract. Publish separate, coarser integration events so the internals can change.
- Delivery is at-least-once in practice, so consumers must be idempotent and tolerate reordering across partitions (see Distributed Systems Patterns).
CQRS
Command Query Responsibility Segregation uses one model to validate and apply writes and one or more different models, shaped for the queries, to serve reads. The read models are derived from the write side.
| It pays when | It does not pay when |
|---|---|
| Read and write load differ by orders of magnitude (100:1 or more) | The app is CRUD and one schema serves both well |
| Reads need shapes the write model cannot serve: full-text search, feeds, aggregates across services | A read replica or a cache would be enough |
| The write model has complex invariants you do not want bent to fit queries | Users must always read their own write immediately everywhere |
- What you give up: read-your-writes. The read side lags by milliseconds normally and by minutes when a projector is behind or broken.
- Mitigations: return the new state in the command response; read from the write store for the author's own recent data; pass a version and have the read API wait until the view has caught up; show "processing" in the UI.
- The levels: same database with separate query classes, then read replicas, then separate stores. Only the last needs a change stream. CQRS does not require event sourcing.
Failure mode: a projector bug writes wrong data to the read store. You need monitoring of projector lag and a way to rebuild a view from scratch.
Event sourcing
Store every change as an immutable event in an append-only log; current state is a fold over the events. Use it when the history is the business (ledgers, order lifecycles, audit-heavy domains). Avoid it as a default persistence choice.
| Piece | Purpose |
|---|---|
| Event log | Source of truth. Append-only, ordered per aggregate, optimistic concurrency on version |
| Projection | A read model built by consuming events; this is where CQRS comes in |
| Snapshot | Cached state at version N so loading does not replay thousands of events; a pure optimisation, safe to delete |
| Replay | Rebuild a projection, or build a new one, from event 1; also how you fix a projection bug |
The hard parts
- Schema evolution: events live forever, so old shapes must stay readable. Add optional fields only; for breaking changes, version the event type and "upcast" old events to the new shape on read.
- Eventual consistency: projections lag. Uniqueness checks ("email not taken") cannot be done against a projection safely; they need a reservation aggregate or a constraint in a synchronous store.
- Deletes and GDPR: an immutable log conflicts with the right to erasure. Options: keep personal data outside the log and reference it by id, or encrypt it per user and delete the key (crypto-shredding).
- Replay side effects: a replay must not re-send emails or re-charge cards. Keep side effects in separate, idempotent consumers.
- Querying: you cannot ask the log "all accounts over 1000"; every query needs a projection.
- Fixing mistakes: never edit an event; append a compensating one.
Sagas, gateways and meshes
| Pattern | One line | Covered in |
|---|---|---|
| Saga | A multi-service transaction as a sequence of local transactions, each with a compensating action; orchestrated or choreographed | Distributed Systems Patterns |
| API gateway | Single entry point for clients: routing, authentication, rate limiting, TLS termination | API and Communication Design |
| Backend-for-Frontend | One gateway per client type (web, mobile) that aggregates and shapes responses for that client | API and Communication Design |
| Service mesh | Sidecar proxies beside every service handle mTLS, retries, timeouts and telemetry for service-to-service traffic | API and Communication Design |
Sidecar, ambassador, adapter
Three ways to add a helper container next to the application container, sharing its network and lifecycle, so cross-cutting behaviour is not compiled into every service in every language.
| Pattern | Direction | Job | Example |
|---|---|---|---|
| Sidecar | General | Extend or enhance the app without changing it | Log shipper, config reloader, certificate rotation |
| Ambassador | Outbound | Proxy the app's calls to the outside: routing, retries, TLS, sharding | Local proxy to a database cluster; a mesh data-plane proxy |
| Adapter | Inbound view of the app | Normalise the app's output to a standard interface | Exporter turning native stats into the monitoring system's format |
Trade-off: you gain language-independent, separately upgradable infrastructure; you pay memory and CPU per pod (multiplied by every replica), an extra local hop of latency, and one more thing that can fail or start in the wrong order.
Platform patterns
Part 4 of 5 · what the services run on
An architect does not need to write manifests but must know what the platform gives for free (restarts, rollouts, discovery, scaling) and where isolation boundaries can be drawn.
- Containers and orchestration
- Service discovery and configuration
- Feature flags
- Multi-tenancy: silo, pool, bridge
- Cell-based architecture: limiting blast radius
- Batch, nearline and online paths
Containers and orchestration
A container packages a process with its dependencies; an orchestrator (Kubernetes is the usual reference) keeps a declared number of them running, replaces failures, rolls out versions and gives them a stable address.
| Object | What it is | What an architect should say |
|---|---|---|
| Pod | One or more containers sharing a network address and volumes; the unit of scheduling | Pods are disposable. No local state that matters; graceful shutdown on SIGTERM |
| Deployment | Declares image version and replica count; performs rolling updates and rollbacks | Readiness probes gate traffic; liveness probes restart hung processes |
| Service | Stable DNS name and virtual IP load-balancing across ready pods | This is built-in server-side discovery |
| Ingress / gateway | HTTP entry from outside the cluster | TLS termination and host or path routing |
| Horizontal autoscaler | Changes replica count to hold a metric near a target | Reactive, takes tens of seconds to minutes; needs resource requests set and a node autoscaler behind it |
| StatefulSet | Pods with stable identity and their own disk | Running databases on the orchestrator is possible but harder; managed services are the common default |
Interview tip: one sentence is enough: "stateless services run as containers on an orchestrator with at least three replicas across zones, autoscaled on CPU or queue depth". Go deeper only if asked.
Service discovery and configuration
Instances change address constantly, so callers look up a name, not an IP. Configuration follows the same rule: it lives outside the artifact so one build runs in every environment.
| Topic | Options | Notes |
|---|---|---|
| Discovery | DNS; a registry (Consul, etcd, ZooKeeper); platform services; mesh | DNS is simplest but TTL caching delays failover. Registries need health checks to evict dead instances |
| Static config | Environment variables, mounted files | Changes need a restart or redeploy; versioned with the release |
| Dynamic config | Config service with watch or poll | Changes in seconds without deploy; treat a config push like a code deploy: review, staged rollout, rollback |
| Secrets | Secret manager, short-lived credentials | Never in the image or the repo; rotate automatically |
Failure mode: the registry or config service becomes a single point of failure. Callers must cache the last known good answer and keep working when it is unreachable.
Feature flags
A flag is a runtime switch that separates deploying code from releasing behaviour. It is the cheapest rollback there is: flip it off, no deploy.
| Flag type | Purpose | Lifetime |
|---|---|---|
| Release | Hide unfinished work; ramp 1%, 10%, 100% | Days to weeks, then delete |
| Experiment | A/B test by user cohort | Length of the experiment |
| Ops / kill switch | Turn off an expensive or optional feature under load | Permanent, tested regularly |
| Permission | Enable per tenant or plan | Permanent |
- Evaluate locally from a cached rule set; never make a network call per flag check. Default to the safe value if the flag service is down.
- Bucket by a stable hash of user or tenant id so a user gets a consistent experience.
- Cost: every flag doubles the paths to test. Stale flags are debt and a known incident cause; give each an owner and an expiry.
Flags as a deployment tool are covered in Reliability and Operations.
Multi-tenancy
How much infrastructure tenants share is a trade between isolation and cost. Most B2B products end up with a pool for small tenants and silos for the few large or regulated ones.
| Silo | Bridge | Pool | |
|---|---|---|---|
| Isolation | Strongest: separate compute, data, often account or network | Data isolated by database or schema; compute shared | Logical only: a tenant_id on every row and query |
| Cost per tenant | Highest; idle capacity per tenant | Medium | Lowest; best utilisation |
| Noisy neighbour | None | In the app tier | Everywhere unless limited |
| Onboarding | Provision a stack (minutes to hours, automated) | Create a schema | Insert a row |
| Operations at 10,000 tenants | Hard: 10,000 deployments and migrations | Hard: schema count limits, slow migrations | Easy: one of everything |
| Per-tenant restore, residency, custom keys | Easy | Possible | Hard |
| Fits | Enterprise, regulated, very large tenants | Mid-market with compliance needs | Self-serve SaaS, many small tenants |
The noisy-neighbour problem
In shared tiers one tenant's burst or heavy query degrades everyone. Controls, cheapest first:
- Per-tenant rate limits and quotas at the gateway; per-tenant concurrency limits inside services.
- Fair queueing: a queue per tenant or weighted scheduling, so one backlog cannot starve others.
- Tenant-aware sharding, and moving a hot tenant to its own shard or silo.
- Per-tenant metrics. Without a tenant label you cannot tell who the neighbour is.
Failure mode: in a pool, one query missing its tenant filter leaks data across customers. Enforce the filter below application code: row-level security, or a data-access layer that cannot run without a tenant context.
Cell-based architecture
Run several complete, independent copies of the stack ("cells") and pin each tenant or user to one. A bad deploy, poison request or overload then hurts one cell, not everyone. With N equal cells the blast radius of a cell failure is about 1/N of users.
- Rules: no cross-cell calls on the request path; each cell has a fixed maximum size that has been load tested; scale by adding cells, not by growing them.
- Deploys: roll out one cell at a time, starting with a canary cell, so a bad change is contained before it spreads.
- Pays with: more infrastructure and lower utilisation, tooling to migrate tenants between cells, harder cross-cell features (global search, a tenant larger than one cell), and the router as a critical dependency.
- Shuffle sharding is a related idea: give each tenant a different random subset of instances so two tenants rarely share all of them.
Senior signal: when asked "how do you limit the damage of a bad deploy or a poison tenant at very large scale?", cells plus staged rollout is the expected answer. It is the same thinking as bulkheads, applied to the whole stack.
Batch, nearline and online paths
Decide per feature how fresh the result must be, then compute it on the cheapest path that meets that freshness. Precompute whatever you can; do online only what depends on the request.
| Path | Freshness | Computes | Strength | Weakness |
|---|---|---|---|---|
| Batch (offline) | Hours to a day | Whole dataset: model training, daily aggregates, full index rebuilds | Cheap per record, easy to re-run, complex logic | Stale; a failed run means yesterday's data |
| Nearline (streaming) | Seconds to minutes | Incremental updates per event: counters, feature updates, index deltas | Fresh without request-time cost | Ordering, late events, state management, reprocessing |
| Online | Now | Per request, inside the latency budget: ranking, filtering, permission checks | Uses live context | Tight budget (tens of ms); cost scales with QPS |
Edge compute: small functions running at CDN points of presence (redirects, auth checks, header rewriting, personalising cached pages) cut a round trip to the origin but have tight CPU and state limits; see Building Blocks for CDNs.
Choosing
Part 5 of 5 · picking a style and defending it
There is no best architecture, only one that fits the team, the load and the consistency needs today, with a clear path to the next step.
A decision flowchart
| If the requirement is | Lean towards |
|---|---|
| Strong consistency across several entities | Keep them in one service and one database; a saga is a cost, not a feature |
| Reads far outnumber writes, or need different shapes | Read replicas first, then CQRS with projected views |
| Complete audit trail, "what was the state on date X" | Event sourcing for that aggregate only |
| Spiky, infrequent or event-triggered work | Serverless functions or queue workers |
| Many consumers reacting to one fact | Publish an event; choreography |
| Very large scale, a failure must not hit all users | Cells, staged rollouts |
| Enterprise tenants with isolation demands | Pool by default, silo for the few |
Anti-patterns
| Anti-pattern | How it shows up | Fix |
|---|---|---|
| Distributed monolith | Services that must be deployed together; lockstep versioning | Re-draw boundaries around capabilities; versioned contracts; merge services that always change together |
| Shared database | Several services writing the same tables | One owner per table; others use its API or events |
| Chatty services | One user request causes dozens of internal calls; N+1 over the network | Coarser APIs, batch endpoints, local read copies, merge the services |
| God service | One service (often "core" or the orchestrator) that every feature must change | Push logic back to the owning contexts; keep orchestrators thin |
| Premature split | More services than engineers; boundaries wrong because the domain was not understood | Start as a modular monolith; split on a measured trigger |
| Synchronous chains | A calls B calls C calls D; latency adds, availability multiplies down (four hops at 99.9% is about 99.6%) | Async where the caller need not wait; cache; fallbacks; flatten the call graph |
| Entity services | Services named after tables, with business logic left in the callers | Split by capability, not by noun |
| Shared domain library | A common library of business models that every service must upgrade together | Share only infrastructure code; duplicate small domain types |
Talking about evolution
Interviewers want to hear a path, not a destination. Start with the simplest thing that meets the stated requirements, and for each step up name the trigger that would justify it.
| Step | Trigger to name | What you now pay |
|---|---|---|
| Replicas, cache | Database CPU dominated by reads; p99 read latency over target | Replication lag, cache invalidation |
| Queue and workers | Requests doing slow or failure-prone work inline (email, thumbnails, third-party calls) | At-least-once delivery, idempotency |
| Modular monolith | Merge conflicts, unclear ownership, changes rippling across the codebase | Discipline and tooling to enforce boundaries |
| First extraction | One module needs different scale, availability or release cadence | Network calls, a second pipeline, distributed tracing |
| Services per context | Deploy queue is the bottleneck; build and test times in tens of minutes | Platform team, sagas, eventual consistency |
| Sharding, CQRS | Write volume or data size past one primary; queries the write model cannot serve | Cross-shard queries, read lag |
| Cells, multi-region | One failure affects all users; latency or residency requirements | Cost, tenant migration tooling, replication conflicts |
Interview tip: a sentence that works: "For the first version I would run this as one service with a replicated database; the first thing I would split out is X, when Y happens, because Z." It shows you know the complex design and chose not to pay for it yet.
Cheat sheet
| Topic | Remember |
|---|---|
| Default shape | Modular monolith until team count, scale divergence or fault isolation forces a split |
| Microservice test | Deployable alone, owns its data, one team, one bounded context |
| Distributed monolith | Separate deploys, shared fate: shared DB, lockstep releases, sync chains |
| Hexagonal / clean | Dependencies point inward; core defines ports, infrastructure implements adapters |
| Bounded context | Where a model and its language are consistent; the service boundary candidate |
| Aggregate | Unit of transactional consistency; reference others by id; one transaction, one aggregate |
| Database per service | No shared tables; joins become API composition or local copies; transactions become sagas |
| Data ownership | One writer per fact; copies are read-only and rebuildable |
| Strangler fig | Facade, move one route at a time, migrate the data, delete the old code |
| Anti-corruption layer | Translate at the boundary so a legacy or vendor model does not leak in |
| Orchestration vs choreography | Central workflow with visible state vs decoupled reactions; orchestrate the critical path |
| Event notification / state transfer / sourcing | Id only and call back / full state in the event / the log is the database |
| CQRS | Separate read models fed asynchronously; you lose read-your-writes on the read side |
| Event sourcing | Append-only log, projections, snapshots, replay; hard: schema evolution, GDPR, lag |
| Sidecar / ambassador / adapter | Helper container: extend / proxy outbound / normalise output |
| Multi-tenancy | Silo (isolated, costly), bridge (shared app, separate data), pool (shared, cheap, noisy neighbours) |
| Cells | Independent full stacks behind a thin router; blast radius about 1/N; deploy cell by cell |
| Serving paths | Batch (hours), nearline (seconds), online (milliseconds); precompute what you can |
| Sync chain arithmetic | Latencies add, availabilities multiply: 0.999 to the power 4 is about 0.996 |
| Evolution answer | Start simple; name the trigger and the cost of each step |
Next: how to keep whichever architecture you chose running, in Reliability and Operations.