Architecture Patterns in Practice
The Architecture Patterns Worth Knowing in 2026, Plus the AI Ones
November 4, 2026 · 12 min read
Software Architecture, Design Patterns, Distributed Systems, AI, App Development
Pattern lists usually come sorted by seniority: learn these first, those later. I find it more useful to sort them by the question they answer. Nobody reaches for a circuit breaker because they're now "mid-level". They reach for it because a dependency started failing and took their app down with it.
So here's my map: five questions every system eventually asks, the patterns that answer each one, and when each is worth its cost. Then a bonus section on the patterns AI features add, because if you build full stack in 2026, there's a good chance an LLM sits somewhere in your request path.
This is a map, not a deep dive. Every pattern here gets a full post with runnable C# and Python in one of two series. The Pattern Map covers the Gang of Four and the cloud patterns (resilience, messaging, caching, strangler fig, sidecar). Architecture Patterns in Practice covers the rest, one group per post:
- Organizing the code: modular monolith, layered and clean, vertical slice
- Screen and app architecture: MVVM, unidirectional data flow, offline-first
- How services talk: API gateway, BFF, pub/sub, event-driven, rate limiting
- Data at scale: CQRS, read replicas, sharding
- Changing live systems: anti-corruption layer, expand and contract, feature flags
- AI: reliable output: structured output, RAG, context engineering, evals
- AI: workflows and agents: chaining, routing, parallelization, orchestrator-workers, evaluator-optimizer, agent loop
- AI in production: MCP, model gateway, guardrails, human in the loop, caching, streaming, durable execution
1. How is the code organized?
This is the first question and the one that's most expensive to get wrong late.
| Pattern | What it is | Reach for it when |
|---|---|---|
| Monolith | One deployable unit | Almost always, to start. Martin Fowler's "monolith first" advice still holds |
| Modular monolith | One deployable, strict internal module boundaries | The codebase grows and teams start stepping on each other, but you don't want a network between them yet |
| Layered / Clean architecture | UI, business logic and data access separated, dependencies pointing inward | Business rules need to outlive the framework or the database |
| Vertical slice | Organize by feature (one folder per use case) instead of by layer | Most changes touch one feature end to end, and layers make you edit five folders |
| Client-server / request-response | A client asks, a server answers | The default for nearly everything; know it well before you leave it |
For app developers, three more belong here:
| Pattern | What it is | Reach for it when |
|---|---|---|
| MVVM | A view model holds screen state; the view just renders it | Any non-trivial screen in SwiftUI, Jetpack Compose or .NET MAUI |
| Unidirectional data flow | State flows down, events flow up, one source of truth | Screens with lots of interacting state. It's the default shape of modern declarative UI, and Android's own architecture guide recommends it |
| Offline-first / local-first | The app reads and writes a local store and syncs in the background | Mobile apps on unreliable networks, which is all of them |
My rule of thumb: a well-structured monolith beats a badly split set of services every time. The modular monolith is the pattern I wish more teams tried before microservices.
2. How do the parts talk to each other?
| Pattern | What it is | Reach for it when |
|---|---|---|
| API gateway | One front door for many services | Clients shouldn't know your internal topology |
| Backend for Frontend (BFF) | One small backend per client type (iOS, Android, web) | Clients need very different shapes of the same data |
| Publish/subscribe | Publishers emit events; any number of subscribers react | One thing happening should trigger several independent reactions |
| Point-to-point queue | One message, one consumer | Work must be done exactly by one worker, at its own pace |
| Event-driven architecture | Services react to facts ("OrderPlaced") instead of calling each other | You want services to change independently. Costs you: harder debugging and eventual consistency |
The trade here is always the same: synchronous calls are simple and couple services together in time; messages decouple them and make the system harder to follow. Pick deliberately.
3. How does it survive failure?
Every network call will eventually fail. These patterns decide whether that failure stays small.
| Pattern | What it is | Reach for it when |
|---|---|---|
| Timeout | Give up after a deadline | Always. A call without a timeout can hang a whole thread pool |
| Retry with backoff and jitter | Try again, waiting longer each time, with randomness | Transient failures. The jitter stops every client retrying at the same instant |
| Circuit breaker | Stop calling a dependency that keeps failing, try again later | A failing dependency would otherwise drag you down with it |
| Bulkhead | Separate resource pools, so one leak can't sink everything | One slow dependency shouldn't starve the others |
| Rate limiting | Cap how fast callers can hit you | Protecting your service (and your bill) from bursts and abuse |
| Idempotency | The same request twice has the same effect as once | Anything retried, which, given the row above, is everything that writes |
If you learn only one row, learn the last one. Retries without idempotency turn "the network blipped" into "we charged the customer twice."
4. How does data stay correct and fast?
| Pattern | What it is | Reach for it when |
|---|---|---|
| Cache-aside | Read from cache; on a miss, load from the database and fill the cache | Read-heavy data that can be slightly stale |
| Read replicas | Copies of the database that serve reads | Reads vastly outnumber writes |
| CQRS | Separate models for writing and for reading | Reads and writes have very different shapes or scale. Overkill for plain CRUD |
| Transactional outbox | Save the data and the "event to publish" in one transaction; publish after | You must update a database and send a message, and can't lose either |
| Saga | A long transaction as steps, each with a compensating undo | A business process spans several services with no shared transaction |
| Event sourcing | Store every change as an event; rebuild state from them | You need a full audit history or time travel. High cost; use sparingly |
| Sharding | Split data across databases by a key | One database can no longer hold or serve it all. Late, and hard to undo |
Each of these has a deep dive with runnable C# and Python:
- Caching: Part 1, every caching strategy and when to use which and Part 2, frontend or backend, every layer
- CQRS and read replicas: Data at scale
- Transactional outbox: dual writes, relays, inboxes and ordering
- Saga: pivots, compensations, isolation and the failure modes nobody draws, plus saga orchestration and sagas with Durable Functions
- Event sourcing: the deep dive (event store, projections, snapshots, versioning), plus the 2025 series starting with the honest truth
- Sharding: shard keys, consistent hashing, resharding and hot partitions
Notice how far down the list sharding and event sourcing are. Both are powerful and both are hard to walk back, so they belong at the end of the road, not the start.
5. How do you change it without breaking it?
The patterns people learn last and need most, because real systems are never built from scratch.
| Pattern | What it is | Reach for it when |
|---|---|---|
| Strangler fig | Put a router in front of the old system and move features to the new one piece by piece | Replacing a legacy system without a big-bang rewrite |
| Anti-corruption layer | A translation layer so a legacy model doesn't leak into new code | Integrating with a system whose concepts you don't want to inherit |
| Expand and contract | Add the new shape, migrate, then remove the old shape | Database and API changes that must not break running clients. Essential for mobile, where old app versions live for months |
| Feature flags | Ship code dark, turn it on separately | Decoupling deploy from release; gradual rollouts |
| Sidecar | A helper process beside the app adds behaviour (proxying, telemetry) | Cross-cutting concerns you don't want in every codebase |
When not to use a pattern
Every pattern in this post costs something: more moving parts, more to learn, more ways to fail. The question isn't "is this a good pattern?" but "is the problem it solves one I actually have?" CQRS on a to-do app, microservices for a team of three and event sourcing for a settings screen all sound reasonable in a design meeting and cost far more than they return. Knowing a pattern includes knowing when it's the wrong answer.
Bonus: the patterns AI adds for full-stack developers
If you put an LLM behind a feature, a new set of patterns shows up. Most are old ideas in new clothes: a tool call is a Command, a model router is a Strategy, a guardrail pipeline is a Chain of Responsibility. Here's the map I'm working from as I learn this space.
Getting reliable output
| Pattern | What it is | Old idea underneath |
|---|---|---|
| Structured output | Constrain the model to a JSON schema instead of parsing free text | A typed contract at the boundary |
| Retrieval-augmented generation (RAG) | Fetch relevant documents and put them in the prompt | A cache-aside for knowledge the model doesn't have |
| Context engineering | Deliberately choose what goes into the context window (instructions, tools, history, retrieved data) | Managing a scarce resource, like memory |
| Evals | Automated test sets that score model output | Unit and regression tests for non-deterministic code |
Workflows and agents
Anthropic's "Building effective agents" names the workflow patterns most teams end up using. Learn these names; they're becoming the shared vocabulary.
| Pattern | What it is |
|---|---|
| Prompt chaining | Split a task into fixed steps, each model call feeding the next |
| Routing | Classify the input, then send it to a specialised prompt or model |
| Parallelization | Run subtasks at once, or the same task several times and vote |
| Orchestrator-workers | One model breaks the task down and delegates to workers |
| Evaluator-optimizer | One model generates, another critiques, loop until good enough |
| Agent loop | The model picks tools in a loop until done. Always give it a stop condition and a budget |
The advice I find most useful from that piece: start with the simplest pattern that works, and only reach for a full agent when a fixed workflow can't do the job. It's the AI version of "monolith first".
Running it in production
| Pattern | What it is | Old idea underneath |
|---|---|---|
| Tool calling via MCP | Expose your app's actions to models through a standard protocol | Adapter |
| Model gateway | One place to route between models, with fallbacks, quotas and logging | API gateway + Strategy |
| Guardrails | Checks on input and output (injection, PII, policy) before and after the model | Chain of Responsibility |
| Human in the loop | An agent proposes; a person approves anything destructive or expensive | Approval workflow |
| Prompt and semantic caching | Reuse expensive context or answers to similar questions | Cache-aside |
| Streaming responses | Send tokens to the UI as they're generated | Server-sent events, progressive rendering |
| Durable execution | Checkpoint long agent runs so a crash resumes instead of restarting | Saga + Memento |
Look at the right-hand column again. The systems knowledge from the first five sections is exactly what makes the AI section manageable. Retries, idempotency, gateways and caches don't go away because a model is involved; agents make them matter more, because an agent will happily retry a tool call that charges a card.
Further reading
- Microsoft, Cloud design patterns (the catalog most of sections 2–5 come from)
- Martin Fowler, Monolith First, Strangler Fig Application, CQRS, Parallel Change (expand and contract)
- Jimmy Bogard, Vertical Slice Architecture
- Sam Newman, Backends for Frontends
- Android Developers, Guide to app architecture
- Ink & Switch, Local-first software
- AWS Builders' Library, Timeouts, retries and backoff with jitter
- Anthropic, Building effective agents and Effective context engineering for AI agents
- Model Context Protocol
- My earlier posts: Design patterns every developer should master and the patterns I keep coming back to
Thoughts on this?
Tell me on X: @bobbyencoded · Share this post on X
Want more like this? Subscribe to The Decode, a weekly email on the AI and developer news worth your time.