CSE Roadmap

Common tier · about 4 hours · 7 parts

Part 3 of 7 · 3 min read

The service-based style

A few large services, one database, and a pragmatic step beyond the monolith.

Think of a hospital with a few big departments: surgery, radiology, pharmacy. Each is run on its own, and they share one patient record system. That is much easier to manage than a hundred tiny clinics.

FSA describes service-based architecture as a hybrid of microservices and the monolith. It calls it one of the most pragmatic styles, because it is distributed without the complexity and cost of microservices or event-driven systems.

The topology has three parts:

  1. A separately deployed user interface.
  2. Several separately deployed, coarse-grained domain services, which are portions of an application, typically 4 to 12, with about 7 on average.
  3. A single, monolithic database shared by the services.

Service-based architecture

Service-based architecture splits an application into a small number of large, separately deployed domain services that usually share one database.

Example: an order system split into Quoting, Receiving, Assessment, Accounting, Recycling and Reporting services, all reading one database.

Services are often deployed like any monolith (a WAR or EAR file), so containers are optional. The UI calls services remotely, usually by REST. An API layer (proxy or gateway) may sit between them, which helps with security, metrics and service discovery.

Why coarse? Each service is large enough to be a whole transaction. The book's checkout example: the order service places the order, generates an id, applies payment and updates inventory inside one service. If the card is expired, a normal database rollback removes everything. In a microservice design, the order would already be saved when the payment service replies "expired", and the system would have to decide what to do about the half-done order and the reserved stock (this is the saga problem from Level 5, module 9). Coarse services give better data integrity. The trade-off is that a change to order placement means retesting and redeploying the whole service including payment, with more risk than a small service.

The shared database causes the main pain. A change to a table can touch every service. The weakest design puts all table entity classes into one shared library, so any table change forces every service to be rebuilt and redeployed. The better design splits the database logically into domains (the book's example: common, customer, invoicing, order, tracking), with one shared library per domain. A change to invoicing tables then affects only the services that use the invoicing library. The common tables are used by all, so changes there need coordination and strict control. The book's rule: make the logical partitioning as fine-grained as possible while keeping well-defined data domains.

A worked example (made up). A system has 7 services and a table change.

Design Services rebuilt for a change to an invoicing table
One shared entity library 7 (all)
Library per domain 1 (invoicing)

Variants. The UI can be split by domain. The database can be split too, as long as no service needs another's data, to avoid calls between services (the book says to avoid those). If the UI and database are both federated, the system has several quanta.

The book's recycling example shows the gains. Quoting and Item Status face customers and need to scale. The others get a single instance each. External and internal operations have separate databases in separate network zones, which is better for security. The Assessment service changes often, and the change stays inside one service, which gives agility, testability and deployability.

Common mistake

Letting service-based services call each other all the time. The book says to avoid calls between domain services. If they need each other that often, the boundaries are wrong.

Check yourself:

  • Why do coarse services keep ACID transactions simple?
  • How does splitting the shared entity library by domain reduce the impact of a table change?