Microservices vs Monolith for Python Backends

Contents

TL;DR

  • Microservices vs monolith comes down to trade-offs: microservices give independent deploys, scaling and team autonomy but add complexity from day one; monoliths are simpler and faster to start but can slow down as everything couples.
  • Size alone isn’t the reason to go microservices: they pay off only when several teams need to release independently, a component has very different scaling, reliability or security needs, or there’s a hard security boundary.
  • For most teams, the sweet spot is a modular monolith: one deployable app with enforced module boundaries, which keeps simple deploys and local transactions while leaving modules ready to be extracted as services later.
  • Framework-wise: FastAPI (or Flask) fits microservices, Django’s batteries-included approach suits monoliths, and both work for a modular monolith.

Should your next backend be one deployable app or a set of services? This post compares microservices and monoliths head-to-head, covers the middle ground most teams should start with (the modular monolith), and maps each approach to Python frameworks. It’s for backend developers who have to make, or defend, that call.

Introduction to microservices and monolithic architectures

There are two main strategies for building and deploying software: microservices and monolithic architectures. Each rests on a different architectural vision.

Microservices advocate for a divide-and-conquer strategy, breaking down complex applications into smaller, more manageable pieces. Each piece, or service, runs independently yet works together as part of a larger ecosystem. This approach offers flexibility in development and deployment, allowing for independent scaling and updating of services.

Conversely, a monolithic architecture takes a unified approach, where all components of the application (from the user interface to the data access layers) are tightly integrated into a single unit. This methodology simplifies deployment and development processes initially but can lead to challenges as the application grows in complexity and size.

Microservices vs Monolithic

The showdown: microservices vs. monolithic

Here are the two architectures side by side.

FeatureMicroservicesMonolithic
DeploymentDeploy services independently, but you now run a deploy pipeline per serviceDeploy the whole application at once
ScalabilityScale the one service that needs itScale the whole application, which is often fine: run more copies behind a load balancer
TechnologyEach service can use a different stack, and then the team has to support all of themUsually one stack, which is simpler to hire for and maintain
ComplexityHigh from day one: network calls, service discovery, tracing, versioned APIsLow to start; grows if module boundaries erode
Development speedSlow to start; independent releases pay off once several teams work in parallelFast to start; slows down when everything depends on everything
ReliabilityA crash can stay inside one service, but every network call is a new way to failA bug can potentially bring down the whole system
DataEach service owns its database; a transaction across services needs sagas or eventual consistencyOne database, and one transaction can cover the whole operation

The “slows down” and “high complexity” entries are opinion; I haven’t measured them.

What’s best for each case?

Choosing between microservices and a monolithic architecture depends on various factors including the size of your project, team expertise, and your specific business needs.

  • Startups & small projects. If you’re just starting out or working on a small project, a monolithic architecture might be your best bet. It’s simpler to deploy, and you won’t have to deal with the complexity of distributed systems early on.
  • Large scale & complex applications. Microservices start to pay off when a specific condition holds: several teams that need to release independently, a component with very different scaling or reliability needs, or a hard security boundary. Size alone isn’t the reason. A large, well-modularised monolith can serve a big product for years (see the next section).

The middle ground: a modular monolith

In practice the choice isn’t binary. A modular monolith is one deployable app whose code is split into modules with hard boundaries, the same boundaries you’d draw between services, minus the network. Shopify famously went this way instead of breaking up its Rails codebase (Deconstructing the Monolith).

In a Python project, that looks like one package per business capability:

app/
├── main.py            # wiring only: create the app, mount each module's router
├── orders/
│   ├── api.py         # HTTP routes for orders
│   ├── service.py     # business logic
│   ├── repository.py  # the orders tables, and nobody else's
│   └── public.py      # the ONLY thing other modules may import
├── billing/
│   └── ...
└── catalog/
    └── ...

The rules that make it work:

  • Modules talk through public.py, never by importing each other’s internals.
  • Each module owns its tables. billing asks orders.public for an order; it doesn’t query the orders table.
  • The boundaries are enforced, not remembered. A tool like import-linter fails CI when one module reaches into another:
# .importlinter
[importlinter]
root_package = app

[importlinter:contract:modules]
name = Modules only import each other's public API
type = independence
modules =
    app.orders
    app.billing
    app.catalog
ignore_imports =
    app.** -> app.*.public

Run lint-imports in CI and a stray from app.orders.repository import ... inside billing fails the build.

You keep the monolith’s simple deploys, local calls and single transaction, and if one module later needs to scale on its own, it already has a clean interface to become a service. Those module boundaries are the bounded contexts from Domain-Driven Design, which I cover in Software Development Best Practices.

Python frameworks for the architectures

Python has frameworks for both models. Here is how the main ones map to each architecture:

  • For Microservices
    • FastAPI (my pick): it’s what I reach for when building a new service. Development moves fast because the API documentation writes itself, and async request handling is there when a service needs high concurrency or throughput. Its type hints double as data validation and serialization, which keeps service code short.
    • Flask. This lightweight and modular framework still works for small services because of its simplicity and flexibility. Its minimalistic design means that developers can add only the components they need, keeping each service lean. You add validation, async and API docs yourself, which FastAPI gives you out of the box.
Python Frameworks
  • For Monolithic
    • Django. As a comprehensive framework, Django is well-suited for monolithic applications with its “batteries-included” approach. An ORM, authentication and an admin panel are built in, so developers can focus on building the core application instead of reinventing the wheel. That makes Django a go-to choice when you want a cohesive development environment and fast prototyping.
Python Frameworks
  • A modular monolith takes both. In Django, each module is an app with its own models. In FastAPI, each module exposes an APIRouter that main.py mounts with app.include_router(...), which is exactly the layout above.

Additional considerations for choosing your architecture

Team structure and size

  • Microservices are well-suited for larger teams. They allow multiple teams to work on different services simultaneously without stepping on each other’s toes. This is the strongest argument for microservices: the service boundaries follow the team boundaries.
  • Monolithic architectures might be more manageable for smaller teams. Since the application is a single unit, it’s easier for a compact team to coordinate their efforts.

Development and maintenance costs

  • Microservices can lead to higher development and maintenance costs initially due to the complexity of setting up separate development, deployment, and monitoring environments for each service. Those costs don’t go away. Shared tooling (templates, a platform team, common observability) makes them smaller, but only once there are enough services to justify it.
  • Monolithic applications might have lower initial costs but can become costly to maintain and scale as the application grows and becomes more complex.

Continuous deployment and integration

  • Microservices excel in environments where continuous deployment and integration are critical. Independent services mean you can update, add, or fix parts of your application without redeploying the entire application, leading to a more agile development process.
  • Monolithic applications redeploy as a whole for every change. With a good pipeline and automated tests that’s routine, not risky; it gets painful when the build is slow or the test suite is weak.

Whichever you pick, a solid CI/CD pipeline does most of the heavy lifting. I cover the basics in Software Development Best Practices.

Real-world examples

To give you an idea of how these architectures are applied, let’s look at a couple of hypothetical examples:

Example 1: E-commerce platform

Imagine you’re building an e-commerce platform. Initially, you opt for a monolithic architecture since it’s quicker to develop and launch. Your app includes user management, product listings, order management, and payment processing in a single codebase.

As your platform grows, you notice that updates are slowing down, and scaling specific functions (like order processing during peak times) is becoming challenging. You don’t rewrite everything as microservices. First you draw module boundaries inside the monolith (orders, payments, catalog). Then you extract only the part with a clear reason to be separate: order processing, because it has to scale on its own during sales. The rest stays a monolith. You pay the distributed-systems cost for one service, not for ten.

Example 2: Blogging platform

You’re developing a blogging platform. Given its relatively straightforward functionality, you stick with a monolithic architecture. It includes user profiles, post creation, comments, and a search feature. This approach helps you keep development swift and maintenance straightforward, as the application’s complexity doesn’t warrant a distributed system.

Years later, the platform has grown, but you find that the monolithic architecture still suits your needs because the application’s complexity hasn’t spiked, and your team has become proficient in efficiently managing the monolithic codebase.

Conclusion

The right choice depends on your project’s needs, your team’s capabilities, and your long-term goals, not on which approach is popular.

My rule of thumb: start with a modular monolith, and extract a service only when you can name the reason: a part that has to scale independently, a separate team that needs its own release cadence, or a component with different reliability or security needs. “Microservices are more modern” isn’t a reason. The architecture is a means to an end, not the end itself.

Python has a framework that fits whichever path you choose. Happy coding!

Back to all Posts