{"canonical_url":"https://engineer.company/glossary/microservices/","content_markdown":"# Microservices\n\n## What it is\n\nMicroservices is an architectural style that splits one application into small\nservices, where every service is a program of its own that runs as a separate\nprocess and can be deployed without the others. James Lewis and Martin Fowler,\nwhose 2014 article gave the style its best-known description, sum it up as\nbuilding applications as \"suites of independently deployable services\". They\nlist what such systems tend to share: services that talk over lightweight\nmechanisms, often an HTTP resource API; services built around business\ncapabilities; deployment that is fully automated; a bare minimum of central\nmanagement; and the freedom for each service to use its own programming language\nand its own storage. They are careful to add that there is no formal definition,\nonly characteristics that most systems carrying the label show.\n\nThe word is younger than the idea. A footnote in the same article records that a\nworkshop of software architects near Venice discussed the term in May 2011, and\nthat the same group settled on \"microservices\" in May 2012. Adrian Cockcroft at\nNetflix had been calling the approach a fine-grained form of SOA, and Lewis and\nFowler make no claim that the style is new: they find its roots at least as far\nback as the principles Unix was built on.\n\nThe alternative it is usually measured against is the monolith: a server-side\napplication built and deployed as one unit. All the logic for a request runs in\none process. With some care the whole application can be run and tested on one\ndeveloper's laptop, and it scales by running more copies of it behind a load\nbalancer. The friction comes later. A small change means rebuilding and\nredeploying everything, a good modular structure is hard to keep over the years,\nand the part that needs more capacity can only be scaled together with\neverything else.\n\nLewis and Fowler define a component as a unit of software that can be replaced\nand upgraded on its own. A library is linked into a program and called in\nmemory. A service is a component outside the process, reached over the network\nthrough a web request or a remote procedure call. The difference matters for\ncoupling. In most languages, only documentation and discipline stop other code\nfrom reaching into a library's internals, while a service can be reached only\nthrough explicit remote calls, so its interface is much harder to bypass. A\nservice may still be more than one process, for instance an application together\nwith a database that only it uses.\n\nThe \"micro\" says less than it seems to. Lewis and Fowler point out that the name\ndraws attention to size and leads to arguments over what counts as micro. The\nlargest services they heard of followed Amazon's two-pizza team, meaning no more\nthan a dozen people, and at the small end they saw a team of half a dozen look\nafter half a dozen services.\n\n## Why it matters\n\nThe first payoff is release on its own schedule. When an application is split\ninto services, many changes need only one service to be redeployed, so one team\ncan ship without waiting for the others. Lewis and Fowler are clear that this is\nnot absolute: a change to a service's interface still has to be coordinated with\nthe services that call it.\n\nThe second is that the software can follow the organisation, rather than fight\nit. In 1968 Melvin Conway argued in Datamation that organisations which design\nsystems are constrained to produce designs that copy their own communication\nstructures. Lewis and Fowler apply this to the usual way of splitting a large\napplication by technical layer, with one team for the UI, one for server-side\nlogic and one for the database. Even a simple change then becomes a project\nacross teams, and logic ends up wherever a team happens to have access. The\nmicroservice style turns that round. Each service covers one business\ncapability, such as orders, stock or payments, from the UI down to storage, and\nbelongs to a cross-functional team with the skills the whole slice needs. That\nteam should own the service for its whole life instead of handing it over at the\nend of a project, and Amazon's version of the rule is that whoever builds a\nservice also runs it in production.\n\nThe third is that the logic stays in the services. Lewis and Fowler sum up the\npreference as smart endpoints and dumb pipes. Services talk through HTTP\nrequests to resource APIs, or through a lightweight message bus that does\nnothing more than route messages, and the deciding happens in the services at\neither end. That is a deliberate step away from the enterprise service bus,\nwhich routes, transforms and applies business rules in the middle of the network\nrather than at its ends.\n\nData is split along the same lines. Each service manages its own database, and\ndifferent services may use different database systems if that suits their work.\nEric Evans's domain-driven design gives the reasoning: a large system holds\nseveral models, and each needs an explicitly bounded context, set in terms of\nteam organisation, of the parts of the application it governs, and of physical\nthings such as code bases and database schemas. The sales view of a customer and\nthe support view of a customer can then differ without anyone having to\nreconcile them in one table.\n\nThe costs are part of the definition, and Lewis and Fowler state them plainly. A\nremote call costs far more than a call in memory, so interfaces between services\nhave to be coarser. Moving code across a service boundary is hard: interface\nchanges must be coordinated, layers of backwards compatibility added, and\ntesting gets more complicated. Distributed transactions are hard to implement,\nso services coordinate without them, accept that consistency may only be\neventual, and repair mistakes with compensating operations. Any call can fail.\nAnd if the services do not fit together cleanly, the complexity has not gone\naway, it has moved into the connections between them, where it is harder to see.\nLewis and Fowler report one argument they consider reasonable: build a monolith\nfirst, give it clean modules, and break it up only once it starts to cause\ntrouble. They add a caveat: an interface that works well inside one process\nseldom makes a good interface between services.\n\n## What it looks like in practice\n\nThe note\n[Selling the last ticket exactly once](/notes/selling-limited-stock-without-overselling/)\nreaches for a service only when one database is no longer enough, and then\nstates the rule that holds the design together: every item has exactly one owner\nof its stock, an inventory service, and nothing else decides. That service is\nsharded by tenant and item, and the largest tenants get cells of their own. Only\nthe reservation of stock has to be synchronous. Payment, the order and the\nreceipt are separate systems, and no transaction spans them. The note rejects\ntwo-phase commit, because it blocks while any participant is slow and payment\nproviders do not take part in it, and uses a saga instead: a sequence of local\nsteps, each with a step that undoes it.\n\nEach step writes its message to an outbox table in the same transaction as the\nchange it announces. In PostgreSQL, a data-modifying statement inside `WITH` can\npass its result to an insert, so the inventory service can reserve a unit and\nrecord the message in one statement:\n\n```sql\n-- inventory service, its own database\nWITH held AS (\n    UPDATE inventory\n    SET available = available - 1\n    WHERE tenant_id = 't-7' AND item_id = 'item-881'\n      AND available \u003e= 1\n    RETURNING item_id\n)\nINSERT INTO outbox (order_id, item_id, event, units)\nSELECT 'A-17', item_id, 'StockReserved', 1 FROM held;\n-- sold out: no row matches, so no message is written\n```\n\nChange data capture then publishes the outbox rows, and every consumer is\nidempotent, keyed by the order, because messages arrive at least once. In this\nsketch no other service touches the `inventory` table: the others learn about\nstock from these messages, or by asking the inventory service.\n\nThe same note also shows where the split belongs in the order of work. In its\nlist of what to do first, giving inventory its own service and its own owner\ncomes fourth, after measuring, after turning the write into one conditional\nstatement and after shedding load with a waiting room, a gate and a cached\nsold-out answer. The cheaper fixes come first.\n\nThe portfolio case\n[A maritime platform built in clean layers](/portfolio/a-maritime-platform-built-in-clean-layers/)\nrecords the founder's architecture contribution under NextMariner and shows the\nother side of the choice. It was a young product whose requirements were going\nto move a lot, and the aim was that changing a business rule should not mean\ntouching the frontend, the API and the database at once. It settled on three\nlayers, each with one job: a Next.js frontend for presentation, a deliberately\nthin Go API that routes, validates, filters for security and orchestrates, and\nall business logic in PostgreSQL functions. The boundaries were written down\nand enforced in review. Lewis and Fowler note that modular lines inside one\napplication take a great deal of discipline to hold, and that the more explicit\nseparation of services makes team boundaries easier to keep clear. This platform\nkept the discipline without splitting its business logic into separate services.\n\n## Where it goes wrong\n\n**Chains of synchronous calls multiply downtime.** When answering one request\nmeans the first service calls a second, which calls a third, the request\nsucceeds only while all three are up, and it waits for each of them in turn.\nLewis and Fowler call this the multiplicative effect of downtime, and cite the\nGuardian's rule of one synchronous call per user request. Keep the synchronous\npath as short as the note keeps it, where only the reservation waits for an\nanswer and everything after it is a message. Give each remaining call a timeout\nand a circuit breaker, the patterns Lewis and Fowler point to in the book\nRelease It!, so that a failing service is cut off instead of waited on.\n\n**Services that always change together.** A split along the wrong lines produces\nservices that cannot be released alone: every feature touches three of them, and\nthey ship in lockstep. Lewis and Fowler give the test: if you keep changing two\nservices together, they should be merged. A related failure is turning method\ncalls into remote calls one for one, which leaves services chatting over the\nnetwork and performing badly. Draw boundaries around business capabilities and\nbounded contexts, make interfaces coarse, and design each service to tolerate\nchanges in the services it calls, so a supplier can grow without breaking its\nconsumers; Lewis and Fowler treat versioning as a last resort.\n\n**Two services share one database.** When the order service reads and writes the\ninventory tables directly, the schema becomes an interface that nobody owns,\nneither team can change it alone, and stock gains a second writer that the\ninventory service's checks never see. Give every piece of data one owner, as the\nnote gives stock one, and have other services ask that owner or read its\nmessages. When an update spans services, use a saga with compensating steps\nrather than a distributed transaction.\n\n**Nobody can follow a request.** A request that crosses several services leaves\na fragment of its story in each one's logs. Lewis and Fowler give real-time\nmonitoring a central place, with technical numbers such as requests per second\nto the database watched side by side with business numbers such as orders per\nminute. They also warn that services reacting to each other's events produce\nemergent behaviour that monitoring has to catch quickly. Trace every request. In\nOpenTelemetry's model, a trace is the path of one request through the system,\nbuilt from spans that share a trace id and point to their parent, and context\npropagation is what lets spans from different services be joined into one trace.\nPass the trace context on every call and with every message, including those\nthat go through the outbox, or the trace ends at the first asynchronous hop.\n\n## Further reading\n\n- [Microservices](https://martinfowler.com/articles/microservices.html)\n  — James Lewis and Martin Fowler, 2014: the nine characteristics, the history\n  of the name, the sidebars on size and synchronous calls, and the case for\n  caution.\n- [How Do Committees Invent?](https://www.melconway.com/Home/Committees_Paper.html)\n  — Melvin Conway's 1968 paper from Datamation, where a system's structure\n  copies the communication structure of the organisation that designed it.\n- [Domain-Driven Design Reference](https://www.domainlanguage.com/wp-content/uploads/2016/05/DDD_Reference_2015-03.pdf)\n  — Eric Evans's summary of the patterns, including bounded context and the maps\n  of how contexts relate.\n- [OpenTelemetry: Traces](https://opentelemetry.io/docs/concepts/signals/traces/)\n  — spans, trace ids, parent spans and context propagation, the pieces that make\n  one request visible across services.\n- [PostgreSQL: WITH Queries](https://www.postgresql.org/docs/current/queries-with.html)\n  — data-modifying statements in `WITH`, which let one statement change a row\n  and record the change elsewhere.\n\n\u003chttps://engineer.company/glossary/microservices/\u003e\n","date_modified":"2026-11-09T21:50:25Z","description":"How a microservice architecture splits one application into small services that are each deployed alone, what that buys, and where it goes wrong.","formats":{"gemtext":"https://engineer.company/glossary/microservices/index.gmi","gopher":"https://engineer.company/glossary/microservices/gophermap","html":"https://engineer.company/glossary/microservices/","json":"https://engineer.company/glossary/microservices/index.json","markdown":"https://engineer.company/glossary/microservices/index.md","pdf":"https://engineer.company/glossary/microservices/index.pdf"},"kind":"page","language":"en","title":"What are microservices?","url":"https://engineer.company/glossary/microservices/","version":1}