Backend

What is Microservices?

An architecture that builds one application as a set of small, independently deployable services, each owning a single business capability and its own data.

Definition

Microservices (or microservices architecture) is a way of structuring an application as a set of small, independently deployable services, each built around one business capability. The widely cited microservices definition from James Lewis and Martin Fowler (2014) adds a few traits: each service runs in its own process, communicates over lightweight mechanisms such as HTTP/REST, gRPC, or a message broker, and can be deployed without coordinating a release with the others. A service typically owns its own data store, so no other service reads its tables directly. The contrast is with a monolith, where UI, business logic, and data access ship as one deployable unit backed by one shared database. In a monolith, calling another module is an in-process function call: fast, transactional, and easy to debug. In microservices the same call becomes a network request that can time out, be retried, or arrive twice. Monolith vs microservices is therefore a trade. You gain independent scaling (run 40 instances of search and 2 of invoicing), independent release cadence, fault isolation, and the ability for separate teams to own separate services end to end. You pay in operational overhead: service discovery, distributed tracing, versioned contracts, and data consistency without cross-service transactions. A handful of microservices design patterns address those costs. Database-per-service keeps each service's schema private. An API gateway gives clients one entry point and handles routing, authentication, and rate limiting. The saga pattern replaces a distributed transaction with a sequence of local transactions, each paired with a compensating action if a later step fails. The strangler fig pattern migrates a monolith gradually by routing one feature at a time to a new service until the old code can be retired. Circuit breakers stop one slow dependency from cascading into a full outage. The best-known microservices example is Netflix. After a major database corruption in 2008, it began moving its monolithic application out of its own data centre into hundreds of services on AWS, finishing the migration in 2016 and open-sourcing tools such as Eureka (service discovery) and Hystrix (circuit breaking) along the way. Amazon, Uber, and Spotify followed similar paths, usually once their monoliths had become a bottleneck for team coordination rather than for raw performance.

When to Use Microservices

Reach for microservices when the bottleneck is organisational: several teams stepping on each other in one codebase, release trains blocked by unrelated changes, or components with very different scaling or reliability needs. They pay off when you already have solid CI/CD, containerisation, centralised logging, and distributed tracing; without that tooling, every new service multiplies the pain. Avoid them for a new product with an unproven domain or a team of a few developers. Service boundaries drawn before you understand the domain are expensive to move, which is why many teams start with a well-modularised monolith and extract services along boundaries that have proved stable (Fowler's "MonolithFirst" advice). A useful test: if two services must always be deployed together, they are really one service.

Microservices in Practice

  • An e-commerce backend split by business capability: orders-service (its own Postgres), inventory-service (its own Postgres), payments-service (wraps Stripe), and notifications-service (consumes events from Kafka). Placing an order publishes an OrderPlaced event; inventory reserves stock and notifications sends the confirmation email, without orders-service calling either directly.
  • A choreographed saga for that order: 1. orders-service creates the order as PENDING and emits OrderPlaced 2. payments-service charges the card and emits PaymentSucceeded or PaymentFailed 3. on PaymentFailed, inventory-service releases the reserved stock and orders-service marks the order CANCELLED Each step is a local transaction; the compensating actions take the place of a rollback.
  • An API gateway route table: GET /api/products/* -> catalog-service:8080 POST /api/orders -> orders-service:8080 GET /api/users/me -> users-service:8080 The mobile app talks to one hostname; the gateway validates the JWT once and forwards each request to the owning service.
  • Strangler fig migration: a Rails monolith keeps serving everything except /search, which the reverse proxy now sends to a new Go search-service. Once search is stable, /recommendations moves next. The monolith shrinks route by route instead of through one risky rewrite.

Common Mistakes

  • Building a distributed monolith: services that share a database or must be released in lockstep get all the network costs and none of the independence.
  • Splitting by technical layer (a 'database service', a 'validation service') instead of by business capability, so every feature change touches several services.
  • Chaining synchronous calls. If one request fans out through five services that are each 99.9% available, the chain is only about 99.5% available and latencies add up; use asynchronous events or caching where possible.
  • Expecting ACID transactions across services. Use sagas, idempotent consumers, and the transactional outbox pattern, and design for eventual consistency.
  • Skipping observability. Without correlation IDs and distributed tracing, debugging a failed request that crossed six services becomes guesswork.

Keep the references coming

One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.