DDD in a Zombie Apocalypse: Frequently Asked Questions
2026-04-02 · [ leer en español ]
In the previous installments we started by building the shelter's vocabulary with the ubiquitous language and ended up with more advanced patterns like the Outbox pattern. It's been an intense ride, but before we close the shelter door, it's time to answer the questions that always come up when you try to apply all this to a real project. We'll also go through a checklist and a short guide to help you decide when DDD makes sense and when it doesn't.
How do I know if something is a Value Object or an Entity?
If you're not sure, use the substitution test. Ask yourself: can I replace this object with an identical one without anything happening?
- Value Object: only its attributes matter. If you've got a can of tuna, you don't care which can it is, as long as it's tuna and weighs 100g. Swap it for an identical one and the system won't notice. What matters is what it is.
- Entity: it has a history and an identity. You can't swap Ana for Borja just because they're the same age. Ana has her past, her relationships and her spot on the guard rotation. What matters is which one it is.
In other words, if the object has an ID that identifies it over time, it's an Entity. If it's just a handful of data, it's a Value Object.
A few examples:
- A walkie-talkie: it depends. If all you need to know is "we have 3 working walkies", it's a VO. If you assign each walkie to a person, with a serial number and a repair history, it's an Entity.
- A food ration: almost always a value object. Nobody cares whether you eat this 100g can of tuna or another one just like it, only how many are left.
- A scouting mission: an entity. It has state that changes over time, people assigned to it, and things that happen to that mission in particular.
When does logic go in the aggregate and when in a Domain Service?
If in doubt, check this little table:
| Case | Where it goes |
|---|---|
| Logic that changes the state of one aggregate | A method on that aggregate |
| Logic that involves several aggregates | Domain Service |
| A stateless calculation or rule that belongs to nobody | Domain Service |
Don't use services to "hollow out" your aggregates (not my best metaphor 😛). If the service does all the work and the aggregate only has getters and setters, you've got an anemic model. The service should orchestrate, but the real logic (the business rules) has to stay protected inside your domain classes.
Do I always need to implement every DDD concept?
No. DDD is a toolbox, and you take out only what you need. You can have Entities and Value Objects without Sagas. You can use the ubiquitous language without implementing Domain Events. You can have Repositories without splitting into Bounded Contexts.
Start with the ubiquitous language and aggregates with invariants. Add the rest when the problem calls for it. The extra complexity only pays off when it solves a real problem you already have, not one you might have someday.
How do I know if my aggregate is too big?
A typical mistake is trying to cram everything into the same place. To figure out whether you should split an aggregate, look at the invariants (remember, the rules that can't be broken).
If a business rule only holds when data A and data B are saved in the same transaction, no matter what, they belong in the same aggregate.
- Example: you can't add a survivor if the shelter is full. The "counter" and the "list" have to go hand in hand, so they stay together.
- Counterexample: a survivor's medical history and the food supplies. When one changes, the other couldn't care less. Split them.
If your aggregate has collections that are rarely modified together, or where a change in one part never affects the rules of another, that's a sign it can be split.
How do I integrate models from different contexts without coupling them?
When Logistics needs to know something only Medical knows, the temptation is to share the class. Don't. It'll wreck the isolation you worked so hard to build.
Use the right tools so contexts can talk without getting coupled:
- Domain events: Medical publishes
OutbreakDetectedwith only the information other contexts need (the affected shelter, the people at risk). No internal medical objects. - DTOs: plain objects with no behavior that represent exactly what the producing context wants to expose.
- Anti-corruption layer (ACL): an adapter in the consuming context that translates what it receives into the local model. If Logistics receives events from Medical, the ACL turns them into logistics concepts, and the logistics model never learns anything about medical histories.
When the consuming context has to understand the internal structure of the producing context, that's a clear sign you should switch to an ACL.
How do I know my domain design is right?
Here's a question to ask yourself: if verifying a domain business rule means spinning up a database or setting up infrastructure mocks, something's off. A pure domain shouldn't need anything external for its rules to be testable.
If, say, the test for "a full shelter rejects new survivors" needs a real repository, that's because you've moved the business logic out of the domain.
Can I use different databases in the same context?
Sure! What draws the line around a Bounded Context is the domain, not the persistence technology.
A context (Bounded Context) is defined by language and business, not by technology. If you manage survivors with PostgreSQL for the data and Elasticsearch for searches, both repositories live in the same context because they talk about the same thing.
That's why the repository interfaces live in the domain:
// Domain - defines WHAT it needs, without knowing HOW
interface SurvivorRepository {
save(survivor: Survivor): Promise<void>;
}
interface SurvivorSearchRepository {
searchBySymptoms(symptoms: string[]): Promise<Survivor[]>;
}
And in infrastructure you have two different implementations, each with its own technology:
// Implements saving
class PostgresSurvivorRepository implements SurvivorRepository { ... }
// Implements search by symptoms
class ElasticSurvivorSearchRepository implements SurvivorSearchRepository { ... }
Both interfaces live in the same context because they serve the same domain model. The application layer uses each one on its own, depending on what each use case needs.
The sign that something belongs in another context isn't that it uses "a different technology". It's that it "talks about different concepts or has a model that drifts away from the rest".
How do I know the system works before the horde shows up?
A system with Sagas and long-running processes can fail in ways that are very hard to see: a transfer that never finishes, a compensation that never runs, or an event that gets published but nobody processes. If you don't have everything under control, these failures show up too late, usually when zombies are already coming through the perimeter.
That's what observability is: knowing what's going on inside the system before everything spins out of control.
First, there's distributed tracing. To follow the whole flow when something goes wrong, use what's called a correlationId, which works like a case number for each process. If you pass it along through every command and event, you can later rebuild the whole route and see where it stopped.
On the shelter's control panel, you should keep an eye on these metrics:
- How long each Saga takes to complete.
- How many end up in compensation.
- How many events are still waiting in the outbox.
- Which error types show up most often.
You can also set up alerts for when a Saga gets stuck, when the compensation rate goes up or when the outbox queue keeps growing. Those cases mean something's wrong, and you'll want to look at it as soon as possible.
Observability is a big topic. If you want to dig into it, Observability Engineering by Charity Majors, Liz Fong-Jones and George Miranda is the most complete reference out there.
Quick DDD checklist
Before you sign off on your implementation, go through these points:
Language and communication
- Is there a glossary of domain terms shared by the whole team?
- Do the names in the code match exactly the ones the business experts use?
- Can you explain the code to someone from the business side without translating in your head?
Aggregates and business rules
- Do the aggregates have methods with business logic, not just getters/setters?
- Are the invariants protected in the aggregate root?
- Is it impossible to break the business rules from outside the aggregate?
Persistence and layer separation
- Are the repositories interfaces in the domain, implemented in infrastructure?
- Does the domain know nothing about SQL, MongoDB or any other persistence technology?
- Do the aggregates expose
toSnapshot()andreconstitute()instead of individual getters? - Can you switch databases without touching the domain?
Events and consistency
- Are events saved to the outbox in the same transaction as the aggregate's state?
- Are the event consumers idempotent?
- Are the command handlers idempotent (do they use a
commandIdto detect duplicates)? - Do transfers between aggregates use eventual consistency instead of transactions that cross boundaries?
- Are invalid intermediate states (like the nomad survivor) modeled as explicit domain concepts?
- Do in-flight Sagas have their state persisted so they survive server restarts?
- Do you have traces and metrics to catch stuck Sagas or an unusual compensation rate?
Bounded Contexts
- Does each context have its own model and language?
- Are there clear contracts between contexts (events, DTOs, APIs)?
- Can you change one context without automatically breaking the others?
- Do you have contract tests to make sure events and DTOs don't break the consumers?
Tests
- Do the tests check domain invariants, not implementation details?
- Can you test the domain without spinning up a database?
- Does every important business rule have at least one test?
- Do the Saga tests check that each event produces the right command?
- Do the Saga tests check that a failure triggers the right compensation?
If you answered "no" to several of these, it may just be that you don't need every DDD tool. But watch out if you answered no to nearly all of them, because there's surely a zombie behind you while you think you're doing DDD.
When to use DDD (and when NOT to)
Not every system needs the engineering of a high-security shelter. A temporary lookout post, a stopover warehouse, a hideout for a single night: each scenario has its own needs and its own costs. Giving a simple CRUD the same architecture as a coordinated evacuation system makes about as much sense as installing decontamination airlocks in a treehouse: it'll cost you, it'll waste your time, and it might come down with the first gust of wind.
DDD isn't a cure-all. It's a powerful tool, but remember: "with great power comes great responsibility".
Anyway, you don't need to go 100% DDD from day one. You can pick out the most complex parts of the domain, apply it there and leave the rest alone. Over time, you can evolve the system bit by bit as it grows and the problems show up.
DDD is a philosophy, not a religion. Take what works for you and apply it where it makes sense.
Use DDD when...
- The domain is complex and keeps changing: interdependent business rules that change often. An insurance management system with hundreds of special cases, a financial trading platform with complex risk rules, or our zombie apocalypse with shelters, infections and coordinated evacuations.
- There are valuable business rules to protect: if your application has logic that can't break under any circumstances, DDD gives you the mechanisms to guarantee it.
- You work closely with domain experts: DDD works best when you can talk directly with the people who understand the business, and those conversations feed straight into the code. If you can't talk to the experts, building a ubiquitous language is pretty much impossible.
- It's a long-term project: DDD has a learning curve that will slow you down at first. But if the project is going to live for many months, or even years, the investment pays off: the code is easier to maintain, new features fit in more naturally, and domain knowledge doesn't walk out the door when someone leaves the team.
DON'T use DDD when...
- The domain is trivial: if your application is a form hooked up to a database with no complex rules, DDD is overkill. A well-built CRUD with Active Record (even if it's considered an antipattern) may well be the right answer, and there's nothing wrong with that.
- You don't have access to domain experts: without working with the people who understand the business, you can't model it properly or build a shared language. Skip that and you'll start slipping assumptions into the ubiquitous language and introducing the wrong business rules.
- You're building a prototype or a short-lived MVP: if you need to validate an idea quickly and don't know whether the project will survive, don't invest in DDD. Build the quick CRUD, validate the hypothesis, and if the project grows there'll be time to refactor toward a richer model. Even more so now that AI can help you refactor in very little time.
- The team isn't ready: DDD requires a solid grasp of OOP, encapsulation and dependency inversion. Trying to apply it with a team that's still learning those basics is a recipe for chaos.
The shelter closes its doors (for now)
With this installment we wrap up the DDD in a Zombie Apocalypse series. Five articles later, we've come a long way. If you've made it this far, first of all, thank you. You now have the tools to make your code speak the language of the domain and survive production without spreading the Z virus.
That said, some topics didn't make it into the articles, either because of length or complexity. They deserve their own space too.
That's why I wrote Domain-Driven Design in a Zombie Apocalypse, a book that works as an alternate story to the Programming Guide for a Zombie Apocalypse and expands on everything we've seen here. On the technical side, it covers the topics from the series plus everything that was left out.
If you found the series useful, the book takes it a lot further.
Remember: keep the doors locked and the code clean!
Other articles in the series
- Part 1: Ubiquitous language, bounded contexts, entities, value objects and aggregates.
- Part 2: Domain services, repositories, the application layer and domain events.
- Part 3: Sagas, antipatterns and tests.
- Part 4: The Outbox pattern, eventual consistency between aggregates and the Snapshot pattern.
If this left you wanting more architecture, Domain-Driven Design in a Zombie Apocalypse tells the whole story: entities, aggregates, bounded contexts, and a shelter that holds up as the project grows. In paperback and on Kindle, with a free sample if you want to look inside first.
To pick up where this article leaves off, the book has:
- Chapter 11, “Sagas”: the "Stuck sagas" section, with timeouts, retry limits and what context to store.
- Chapter 14, “Event Storming”: the workshop phase by phase, from the wall to the code.
- Appendix A, “When to use DDD (and when not to)”.
- Appendix B, “DDD in other domains”: an online store, a streaming platform and a pharmaceutical company.
- Appendix C, “Frequently asked questions”: more questions like the ones in this article.