# Microservices

> Building one application as many small services that each do one job.

- Level: Advanced
- Topics: Software, Cloud
- URL: https://tidbit.legios.com.ar/microservices/
- In Spanish: [Microservicios](https://tidbit.legios.com.ar/es/microservices/)

**Microservices** is a way of structuring software in which an application is split into many small, independent services. An online shop might have one service for users, one for the catalog, one for orders and one for payments. Each runs on its own, usually in its own container, often owns its own database, and talks to the others only through APIs or messages in a queue.

The alternative is a **monolith**: one program that contains everything and is deployed as a single piece. Monoliths are simpler to build, test and understand, which is why most products start as one. Trouble appears when the code and the team get large: a small change requires redeploying the whole thing, one slow part drags down the rest, and dozens of people step on each other's toes.

Microservices answer that by letting each team own a service, change it and deploy it on its own schedule, and scale only the parts under load. The price is complexity. A function call inside one program becomes a network call that can be slow or fail; a single database transaction becomes coordination across several services; and finding a bug means following a request through many logs. Done without need, it creates a "distributed monolith" with the problems of both. Tools like Kubernetes, load balancers and tracing exist largely to manage this.

## An analogy

A monolith is a single restaurant kitchen where every cook shares one stove. Microservices is a food court: each stall has its own kitchen, menu and staff, and can renovate without closing the others, but now someone has to coordinate orders that need food from three stalls.

## Keep in mind

- Each service does one job, can be deployed alone, and usually owns its own data.
- Services talk over the network through APIs or message queues.
- Gains: independent teams, deploys and scaling. Costs: network failures and operational complexity.
- Many teams start with a monolith and split it only when it hurts.

## Go deeper

- [Microservices, by Martin Fowler and James Lewis](https://martinfowler.com/articles/microservices.html)
- [What are microservices? (AWS)](https://aws.amazon.com/microservices/)
- [Microservices on Wikipedia](https://en.wikipedia.org/wiki/Microservices)

## Related terms

- [Container](https://tidbit.legios.com.ar/container/): A sealed box with a program and everything it needs to run anywhere.
- [Database](https://tidbit.legios.com.ar/database/): An organized store of data that programs can search and update safely.
- [API](https://tidbit.legios.com.ar/api/): The menu of things one program lets another program ask for.
- [Bug](https://tidbit.legios.com.ar/bug/): A mistake in software that makes it behave differently from what was intended.
- [Kubernetes](https://tidbit.legios.com.ar/kubernetes/): The system that runs and babysits containers across many machines.
- [Load balancer](https://tidbit.legios.com.ar/load-balancer/): The traffic cop that spreads incoming requests across many servers.
