Domain-driven design
21 questions in 6 subtopics.
Entities and value objects
What is the difference between an entity and a value object in domain-driven design? Give Java examples and explain how equals andhashCode differ for each.Design a Money value object in Java for a payments service. Which representation, operations and checks do you include, and which mistakes do you avoid?A JPA entity implements equals and hashCode using its database-generated id. A new entity is added to a HashSet before being persisted; after persist and flush, set.contains(entity) returns false. Explain and fix.Your company has tried twice to build a single canonical enterprise data model, with one Customer and one Product shared by all systems. Both efforts stalled. Why do these efforts usually fail, and what should you do instead?Aggregates
What is an aggregate and an aggregate root in DDD? Why should one aggregate refer to another only by id?Two users add items to the same shopping cart at the same moment. The rule is that a cart holds at most 50 items. Using a Cart aggregate with JPA, how do you guarantee the rule under concurrency?An Order aggregate includes its line items, payments, shipments and the full history of status changes. Some orders have 10,000 line items, and loading an order for any change is slow and conflicts often. How would you redesign the boundaries?Repositories
How does a repository in DDD differ from a DAO, and how does Spring Data fit into this?Should a Spring service annotate its domain classes directly with JPA annotations, or keep a separate persistence model and map between them? Discuss the trade-offs and when you would choose each.Several services read and write the same database tables directly, so no service clearly owns the data. Plan the move to one owner per aggregate, accessed through that owner's repository and API.Domain events
What is a domain event? How should it be named, and how does Spring Data help an aggregate publish events?Order service must publishOrderPlaced to Kafka whenever an order is saved, with no lost or phantom events. Design this.Teams publish fine-grained domain events from inside their services, and other teams have started consuming them directly. Now any internal change breaks consumers. How do you separate internal domain events from integration events?A chief architect proposes event sourcing as the company-wide architecture for all new services. Evaluate this as a multi-year bet.Bounded contexts
What is a bounded context? Explain how the word Customer can mean different things in Sales, Billing and Support, and how bounded contexts map to services or modules.You are splitting a large monolith across eight teams. How do you find bounded contexts and align them with team ownership?Over a ten-year horizon, how do you govern bounded context boundaries as the business changes through new products, acquisitions and reorganisations?Anti-corruption layer
What is an anti-corruption layer, and why should domain code not use an external system's API classes directly?Your Spring service must integrate with a legacy ERP that uses cryptic codes, overloaded fields and inconsistent error handling. Design an anti-corruption layer for it.During a strangler fig migration from a legacy system to new services, where do you place anti-corruption layers, and how do you avoid them becoming permanent?Your company acquires another business whose systems use different models for customers, orders and products. Over several years, how do you integrate the acquired platform?No question matches these choices.