CSE Roadmap

Core tier · about 4 hours · 8 parts

Part 2 of 8 · 3 min read

What a microservice is

Small services, each with its own process and its own data.

Think of a food court. Each stall cooks its own menu, has its own till and its own staff. If one stall closes, the others keep selling. A restaurant with one kitchen is different: when the kitchen stops, everything stops.

Microservices architecture

A microservices architecture builds a system from many small services. Each service runs in its own process, does one job for one area of the business, and owns its own data. Services talk to each other only over the network.

Example: a shop with separate catalog, cart, payment and shipping services, each with its own database.

FSA traces the idea to domain-driven design (DDD), a way of designing software around the business domain. One DDD idea matters most: the bounded context. A bounded context is a boundary inside which every name and data shape is private. Page 6 covers how to draw these boundaries. For now: inside a context the code and the database schema are tied together, but nothing outside may depend on them.

Bounded context

A bounded context is a part of a system with its own code, its own model and its own data schema, which no other part may reach into.

Example: the word "customer" in billing holds a card and an address. In shipping it holds only a name and a delivery point. Each context keeps its own version.

Two consequences follow, and FSA stresses both. First, the style prefers some duplication over sharing. A shared Address class is convenient, but it ties two services together. The First Law of Software Architecture (page 1) says that every choice is a trade-off, and reuse trades away independence. Second, the service is domain-partitioned (page 3). A service is cut along a business area, not along a technical layer.

BM compares the style with older tools. A shared library cannot use another language, cannot be scaled alone, and cannot be released without redeploying the process that loads it. A module system inside one process has the same limits. BM adds an observation from experience: modules in one process drift into tight coupling, because nothing forces them apart. A process boundary makes the wrong dependency harder to write. BM also says microservices are one specific way of doing service-oriented architecture (SOA), in the way that Scrum is one way of doing Agile.

A worked example (made up). A team has one codebase with 40 pages of orders code and 25 of stock code. A developer calls Stock.reserve() straight from the orders code, which saves an hour. In a monolith the call works. In microservices, the same shortcut is impossible: stock lives in another process with another database. The developer must call the stock service's published interface, and it must answer when the network is slow. The cost is higher on the day. The gain is that stock can change its tables freely, as long as the interface stays the same.

Check yourself: 1. Why does a bounded context allow duplicated code? 2. A team shares one database between three services. Is this still microservices? Why or why not? 3. Name two limits that a shared library has and a separate service does not.