Whose method is upgrade?
An airline wants its frequent flyers to pay for a cabin upgrade with points. A member holding an economy ticket can move to business up to 24 hours before departure, and the price in points depends on three things: the flight's distance band, the fare paid, and the member's tier. A discounted economy ticket from Lisbon to Toronto upgrades for 60,000 points; a gold member pays 48,000, because gold takes 20 percent off; the cheapest basic fares cannot be upgraded at all. The developer who picks up the ticket has the rule written down and one question left: which class gets the upgrade method?
Booking looks like the obvious home. It knows the flight, the fare and the cabin. But to take the points it would have to be handed the member's LoyaltyAccount and change its balance, so one aggregate would be changing another's state from the inside. LoyaltyAccount.upgrade(booking) is the mirror image: an object whose job is a points balance would learn fare classes and distance bands. Either way the pricing rule hides in whichever class won the argument, and the next developer looking for how upgrades are priced has to guess which one that was.
The upgrade is something the business does with a booking and an account, not something either of them does alone. Eric Evans gave the home for that kind of operation a name, Domain Service: a class in the domain layer that holds one operation fitting no single entity or value object, often because it spans several aggregates. The airline's staff call it "upgrade with points", so the service is PointsUpgrade, with a single method that takes the booking and the account. The name comes from the people who sell upgrades, not from the code's habits (UpgradeManager, BookingHelper), which is what Subdomains & ubiquitous language asks of every name in the model.
The price lives here, the balance does not
Inside PointsUpgrade, the service holds the part of the rule that needs both objects, and nothing else. It reads the fare and the distance band from the booking and the tier from the account, works out 48,000 points, and then asks each aggregate to change itself: account.redeem(48000) and booking.upgradeToBusiness(). It never writes a balance or a cabin field. The account still refuses to go below zero, and the booking still refuses an upgrade on a basic fare or inside 24 hours of departure; those rules belong to them and stay with them. Holding a free business seat for the passenger is the flight inventory's business, a third object this example leaves out.
The service is stateless: it keeps no state of its own from one call to the next, no current booking, no running total. Given the same inputs and the same pricing rules, it computes the same price, and one instance can be shared by every request as long as its collaborators are safe to share. A test of the price needs only a booking and an account, while a test of the 24-hour cut-off also needs a clock the test controls. In this example it takes domain objects and returns one: an UpgradeConfirmation value with the new cabin and the points charged, not a request body or a database row.
The application service loads both aggregates and calls PointsUpgrade, which prices the upgrade and asks each aggregate to change itself. Repositories and the transaction stay with the application service.
Handed two aggregates, not a transaction
PointsUpgrade is handed the booking and the account; it neither loads nor saves them. The domain service holds a business rule, while fetching, saving and deciding the transaction belong to the use case's Application Service (DDD), and infrastructure implementations stay out of both, behind a Repository. Keeping SQL, ORM sessions and HTTP calls out of the domain service is what lets the price be tested without a database; if it ever needed outside data, such as a partner airline's award chart, the domain would declare an interface and infrastructure would implement it.
In the first week a member's redemption was saved, the save of her booking then failed a version check, and she lost 48,000 points and kept her economy seat. Changing two aggregates is not atomic by default, even inside one service call: either the application service commits both changes in one transaction, when both writes can take part in the same atomic transaction, or each aggregate is changed in its own transaction and the other change follows through events, with compensation if it fails, here crediting the points back. Aggregate explains why one aggregate per transaction is the usual rule and when to break it; a process built from such steps and compensations is a Saga.
When every method becomes a service
Domain services are easy to like, and that is their risk. A few months on, the airline's code has PointsService.deduct(account, points), which checks the balance and then sets it, and a PointsExpiryService, written by another team, which sets it too, without the check. The account is now a set of fields with getters and setters, and the rule that a balance never goes negative lives wherever someone remembered to write it. That is an anemic domain model: objects that hold data and no behaviour, with the behaviour spread across services, the procedural design that putting rules on the objects was meant to replace.
The test is short. An operation that reads and changes one aggregate is usually a method on that aggregate: redeeming points is account.redeem, expiring them is account.expire. A domain service earns its place when the rule needs several domain objects and none of them is the natural owner, as with the upgrade price, a calculation drawing on several objects, or a transfer of points between two members' accounts. When a service's methods take one object and set its fields, move them back onto the object. And when part of the rule, such as is this booking upgradeable?, starts being needed in several places, it can become an object of its own, a Specification.
Earning a node in the Challenge
One of the six requirements in the DDD Tactical Building Blocks Challenge is "Model a Domain Service holding logic that spans multiple aggregates". A node called BookingService wired to everything meets it only on paper. Pick the one operation in your use case that, like the upgrade price, needs two aggregates and belongs to neither, name the node after it, and connect it to those aggregates and to the Application Service that calls it. Then check it once more: if the operation fits one of those aggregates naturally, it goes there and the node does not. The node earns its place when no entity or value object owns the operation, and plain coordination, loading, calling and saving, belongs to the Application Service.