Monolith or Microservices
A monolith is one program that handles every part of an application. Microservices split an application into small separate services, and each service handles one part.
A request inside a monolith
One program answers the request on its own. The whole path takes 1 step.
steps = ["monolith answers the request"]
for step in steps:
print(step)
print("steps:", len(steps))The same request through services
Four services pass the request along in turn. The whole path takes 4 steps.
steps = [
"service 1 receives the request",
"service 2 finds the photo",
"service 3 loads the photo data",
"service 4 builds the answer",
]
for step in steps:
print(step)
print("steps:", len(steps))Counting deployable parts
A monolith deploys as a single part. The service shape deploys as 4 separate parts.
monolith = ["the whole program"]
services = ["photos", "accounts", "search", "billing"]
print("monolith deployable parts:", len(monolith))
print("microservices deployable parts:", len(services))Example
monolith_steps = ["monolith answers the request"]
service_steps = [
"service 1 receives the request",
"service 2 finds the photo",
"service 3 loads the photo data",
"service 4 builds the answer",
]
print("monolith steps:", len(monolith_steps))
print("microservices steps:", len(service_steps))
print("monolith deployable parts:", 1)
print("microservices deployable parts:", len(service_steps))Key points
- Monolith: One deployable program holds all the parts of an application.
- Deployable part: A part that can be put into use on its own.
- Microservices: Separate small programs each own one part of an application.
- Monolith strength: A request stays inside one program, so its path is short and easy to follow.
- Microservices strength: One service can be changed, deployed or scaled without touching the others.
- Monolith cost: A fault in one part can bring down the whole program.
- Microservices cost: A request crosses program boundaries, so each crossing can add delay or fail.
In this example, one request takes 1 step inside the monolith and 4 steps through the services. The service shape also has 4 deployable parts instead of 1, and that extra freedom is what its extra steps pay for.
Note
Neither shape wins on its own, and the right choice depends on the size of the team and the system.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
A team wants to deploy and scale the search part on its own, without touching the rest of the system. Which shape gives them that?