Part 5 of 8 · 3 min read
Granularity and communication
How small is small enough, and how services talk.
The word "micro" misleads. FSA quotes Martin Fowler: the term is a label, not a description. It was chosen to contrast with the very large services of earlier SOA. Treating it as an order to go small leads to the commonest mistake: services so small that each needs five others to finish one task.
FSA gives three guides for finding a boundary:
| Guide | The question |
|---|---|
| Purpose | Does the service do one significant job in the business? |
| Transactions | Which entities must change together? Keep them in one service |
| Choreography | Do two services talk to each other all the time? Then merge them |
FSA adds that nobody gets this right on the first pass. Boundaries come out of iteration.
Read it as
A good service boundary is where the talking stops. If two services exchange a message for nearly every request, they are one service split in half.
Next, the entity trap (FSA's term from earlier chapters): making one service per database table, such as a Customer service, an Order service and an Address service. This is cutting by data shape and not by business job, and it leads to many calls and many transactions.
Communication is the second choice. Calls are synchronous (the caller waits for the answer) or asynchronous (the caller sends a message and carries on). FSA describes microservice communication with a mouthful: protocol-aware, heterogeneous interoperability. In plain words: no central hub sits between services, so each service knows how to call the others; services may use different languages; and they call each other over the network.
For asynchronous work the style borrows the event-driven machinery of page 4. The two topologies from that page return under new names:
| Page 4 name | Microservices name | Control |
|---|---|---|
| Broker | Choreography | No central coordinator. Each service reacts to events |
| Mediator | Orchestration | One service runs the whole flow |
FSA keeps both. Choreography respects the bounded-context idea and is faster, but errors and coordination get harder. A choreographed first service often grows into a coordinator in disguise. FSA calls that the front controller pattern, and the cost is a more complex service. Orchestration puts the coordination in one place and couples the services to it. FSA's conclusion is that the best choice depends on the workflow, since some business processes are tightly linked by nature.
FSA also warns against a central API layer that holds business logic. An API layer is fine as a front door for routing and discovery. If it becomes the coordinator, the logic has left the bounded contexts. Page 7 returns to this choice in depth.
For the user interface, FSA names two layouts. One is a single monolithic frontend that calls through the API layer. The other is the microfrontend: each service supplies its own screen component, and a shell page assembles them, so one team can own a feature from screen to database.
Check yourself: 1. Orders and Customers call each other four times per request. What does the choreography guide advise? 2. Which page 4 topology is orchestration closest to? 3. Why is a business-logic API layer against the grain of the style?