React / 28
Monolith vs microservices
Two ways to organise the servers behind your app. One big app that ships as a whole, or many small services that each do one job.
One app, or many?
Monolith
one codebase · one deploy
Change one line in Payments and you redeploy all of it.
One database
Microservices
many small apps · deployed separately
one address for users
app.example.com
Web UI · React
/
own deploy · own data
Menu API
/api/menu
own deploy · own data
Orders API
/api/orders
own deploy · own data
Payments API
/api/payments
own deploy · own data
Monolith: everything in one place
A monolith is one codebase that ships as one unit: the pages, login, menu, orders, payments and emails all live together and usually share one database.
It's the right default for most new projects:
- Simple: one repo, one build, one deploy, one thing to debug.
- Fast inside: parts call each other as plain function calls, not over the network.
It starts to hurt as it grows:
- Builds and start-up get slow, and every small change redeploys everything.
- A crash in one module can take down the whole app.
- You can't scale just the busy part. Lunchtime order traffic means scaling all of it.
- Switching a framework or language means touching the whole codebase.
Microservices: one job per service
Microservices split the same jobs into small, separate apps. Each service:
- does one job (menu, orders, payments). This is the single responsibility idea.
- is deployed on its own, often by its own team.
- usually owns its own data.
- can use whatever language or database suits that job.
They talk over the network, usually with HTTP requests that send and receive JSON (often called a REST API), or by passing messages through a queue.
| Monolith | Microservices | |
|---|---|---|
| Deploy | Everything at once | Each service on its own |
| Scaling | Scale the whole app | Scale only the busy service |
| A bug crashes… | Possibly everything | Usually just that service |
| Team setup | Everyone in one codebase | A team per service |
| Hardest part | Growing size | Network calls, monitoring, keeping data in sync |
Where your React app fits
In both setups, your React app is the UI. After npm run build it's just static files (HTML, JS, CSS). The browser downloads them, then calls the backend with fetch:
// Same code whether the backend is a monolith or ten services
const res = await fetch("/api/orders");
const orders = await res.json();On your laptop, each service usually runs on its own port: the React dev server on localhost:5173, the orders API on localhost:3000, and so on. In production, users see one domain. A gateway (a reverse proxy) sits in front and forwards each path to the right service: / to the UI, /api/orders to the orders service.
Which should you pick?
Don't
Start with ten services
A side project or a new startup split into many services on day one. You spend your time on deploys, networking and debugging across services instead of on features.
Do
Start modular, split when it hurts
Build one app with clear folders per area (menu, orders, payments). Pull one out into its own service when there's a real reason: it needs to scale alone, deploy alone, or a separate team owns it.
Gotchas
Recall
Can you answer these?
0/4
Answer out loud (or in your head) before you tap. That's what makes it stick.
Saved on this device only. No login.
