Lesson 28 of 28Decisions and evolution
Wrap-Up: Design & Architecture
Tie the whole course together: one real feature taken from a tangled monolith to a clean, guarded design, a mixed review, and where to go next.
You started this course with SOLID and a single class that did too much. Since then you have learned the classic patterns, refactored real code, measured coupling, split backends into layers and modules, modelled a business with domain-driven design, and learned to test, secure and evolve what you built. On the job these ideas never arrive one at a time. This lesson lines them up once more, then uses them together on one piece of work.
The path you took
Unit 1
Principles
SOLID, clean code and the design patterns gave you a vocabulary for why code is hard to change, which you need before you can fix real codebases.
Unit 2
Keeping code healthy
Smells, safe refactoring, technical debt, coupling metrics and a functional core taught you to improve code that already exists, ready to shape whole systems.
Unit 3
Architecture
Layers, hexagonal design, React structure, modular monoliths and events showed where boundaries go, which raised the question of where the business lines are.
Unit 4
Domain-driven design
Bounded contexts, aggregates and event sourcing let you draw those lines from the business, so the next unit could check they hold.
Unit 5
Quality and safety
Testing strategy, contract tests, threat modeling and the anti-patterns gave you ways to prove a design works and is safe, before it ships.
Unit 6
Decisions and evolution
APIs that last and fitness functions keep a good design good while the code, the team and the business keep changing.
Now
Wrap-up
One job that uses all six units in the order you would really reach for them.
How it fits together
The ticket: "We are opening the shop to third-party sellers. Sellers list products, we take a commission on each sale, and we pay sellers out weekly. Launch in one quarter." The shop is a three-year-old FastAPI monolith with one Postgres database and twenty engineers. Here is how the course shows up, in the order you would really work.
Reading the ground. Before designing anything, you look at where the new feature will land. The orders.py module is 3,000 lines, with a process_order function that prices, charges, emails and writes to four tables. You name what you see with Code Smells and Refactoring: a long method, shotgun surgery on every pricing change, and feature envy toward the payments code. You run the fan-in and fan-out numbers from Coupling, Cohesion, and Dependency Rules and find an import cycle between orders and catalog. You do not fix all of it. Technical Debt taught you to pay down only the debt that sits on the path of the work, and to say so in business terms: "marketplace touches checkout, and checkout changes take three times longer than anything else."
Finding the boundaries. "Seller" means three different things in the code: a user account, a payout recipient, and a catalog owner. That is the signal from Domain-Driven Design: Bounded Contexts. A short EventStorming session gives you three contexts: Catalog, Ordering, and a new Payouts context with its own language ("statement", "hold", "settlement"). Payouts is core to the new business, so it gets your best modelling. Tax calculation is generic, so you buy it and wrap the vendor SDK behind an anti-corruption layer.
Choosing the shape. Microservices are tempting and wrong here. Monolith vs Microservices and The Modular Monolith point to one deployable with real internal walls. Payouts becomes a module with a public API, its own tables, and no other module reading them. Architecture Anti-Patterns reminds you why: a Payouts service that read the orders table directly would be a distributed monolith on day one.
Building the module. Inside Payouts you follow Layered Architecture and Python Backend Architecture: a thin router, a service per use case, repositories behind interfaces, and a unit of work around each transaction. Hexagonal and Clean Architecture keeps the bank API on the outside as a driven port, so the use cases never import an HTTP client. The commission rules (a flat rate, a category rate, a promotional rate) are a Strategy from Behavioral Patterns, picked by a small factory from Creational Patterns. The vendor tax SDK sits behind an Adapter from Structural Patterns. The maths itself is pure functions over immutable data, the design from Functional Core, Imperative Shell, so a payout statement can be computed and tested without a database.
Modelling the rules. A weekly Statement is an aggregate from Domain-Driven Design: Aggregates and Entities. It owns its lines and enforces its invariants: it cannot be paid twice, and its total always equals the sum of its lines. Money is a value object, never a float. Two admins approving the same statement at once is one of the races from Concurrency Patterns, and a version column on the aggregate closes it with optimistic concurrency.
Connecting the modules. Ordering should not call Payouts on every sale. It raises an OrderCompleted event, following Event-Driven Architecture. The event is written in the same transaction as the order through an outbox, and the Payouts consumer is idempotent, because the broker will deliver some messages twice. Finance asks "why was this seller paid this amount?" You considered full Event Sourcing and CQRS in Depth and chose a plain append-only ledger table instead. You record that choice, and its reason, in an ADR.
Proving it works. Testing Strategy gives you fast unit tests on the functional core, integration tests at the repository seam, and a handful of end-to-end tests on the money path. The seller dashboard is a separate React app built with React Architecture: features grouped by folder, server state kept apart from UI state. It depends on the payouts API through a consumer-driven contract from Contract Tests and Architecture Tests, so a breaking field rename fails CI, not production.
Making it safe. Sellers can upload product images and change bank details. Threat Modeling and Security by Design walks that flow with STRIDE. Changing bank details is a spoofing and tampering target, so it needs re-authentication, a notification to the old address, and a 48-hour payout hold.
Keeping it good. The public seller API follows Designing APIs That Last: additive changes only, a deprecation process, and a spec checked in CI. Finally, Evolutionary Architecture and Conway's Law turns your boundaries into fitness functions. An import-linter contract fails the build if anything imports Payouts internals, and a new Payouts team owns the module, so team lines match code lines.
No lesson worked alone. The bounded context told you where the module went, the module told you where events were needed, and the events told you which consumers needed to be idempotent. That chain, from business language to enforced boundaries, is what architecture work looks like.
Check yourself
What does this print?
seen = set()
balance = 0
def handle(event):
global balance
if event["id"] in seen:
return
seen.add(event["id"])
balance += event["amount"]
events = [
{"id": "e1", "amount": 10},
{"id": "e2", "amount": 5},
{"id": "e1", "amount": 10},
]
for e in events:
handle(e)
print(balance, len(seen))Match each problem to the tool from this course that solves it.
Put the steps of safely restructuring a tangled module in order.
- Tap the steps below in the right order.
What you can do now
- Read an unfamiliar codebase, name its smells and coupling problems, and refactor them in small, safe steps.
- Apply SOLID and the common patterns when a real change calls for them, and argue against them when it does not.
- Structure a backend into layers or ports and adapters, and a frontend by feature.
- Draw module and service boundaries from the business, and connect them with events that survive duplicates and failures.
- Choose a test mix, add contract and architecture tests, and run a basic threat model on a new feature.
- Explain a design decision and its trade-offs in a review or an ADR, and guard it with a fitness function.
That is solid mid-level design skill. What it is not yet is the judgement that comes from living with your own decisions for years. That comes from shipping systems and watching them change.
Mistakes that still catch people
- Abstracting before the second case. Interfaces and factories for one implementation slow everyone down. Revisit SOLID Principles and Architecture Anti-Patterns.
- Splitting into services to fix a messy codebase. The mess comes along, now with network calls. Revisit Monolith vs Microservices and The Modular Monolith.
- Sharing tables across boundaries. One shared table quietly couples every module that touches it. Revisit The Modular Monolith and Domain-Driven Design: Bounded Contexts.
- Assuming events arrive once and in order. They do not. Revisit Event-Driven Architecture.
- Refactoring without pinning behaviour. A cleanup that changes behaviour is a bug fix nobody asked for. Revisit Code Smells and Refactoring.
- Trusting code review to hold boundaries. Reviewers miss imports. Revisit Coupling, Cohesion, and Dependency Rules and Evolutionary Architecture and Conway's Law.
Where to go next
The natural next course is System Design. This course shaped the inside of a system; System Design scales it out across machines, with caches, queues, replicas and the trade-offs interviewers probe. After that, Engineering at Work covers the design docs, RFCs and ADRs that carry these decisions through a team.
Real practice matters as much as the next course:
- Refactor something real. Take a project of your own, find its worst module, pin it with tests and restructure it into a module with a public API and an import rule in CI.
- Read mature open-source codebases. Look at how a large project such as Django or a popular TypeScript framework draws its internal boundaries, and read its design discussions.
- Read the primary sources. Martin Fowler's site on refactoring and architecture, the Domain-Driven Design reference, and the docs for import-linter or dependency-cruiser.
- coupling
- How much one module must know about, or change with, another; lower coupling makes change cheaper.
- bounded context
- A part of the system where one model and one vocabulary apply consistently.
- aggregate
- A cluster of objects treated as one unit for changes, which enforces its own invariants.
- modular monolith
- One deployable split into modules with public APIs and owned data, and enforced boundaries between them.
- outbox
- A table written in the same transaction as the business change, from which events are published reliably.
- fitness function
- An automated check, usually in CI, that measures whether the architecture still meets a chosen quality.
- ADR
- Architecture decision record: a short document stating a decision, its context and its consequences.