Book a free call

SaaS Microservices Architecture: How to Structure It

Microservices can make a SaaS product easier to scale and change, or harder to run. Here is how to draw service boundaries, handle tenants and keep it operable.

Hertiv engineering teamReviewed by a senior engineer
7 min read
SaaS Microservices Architecture: How to Structure It
On this page

Short answer

A SaaS microservices architecture builds a software-as-a-service product as a set of small, independent services instead of one large application. Each service owns one part of the product, such as billing or user accounts, and talks to the others through defined interfaces, so teams can change and deploy one service without redeploying the whole product.

What is a SaaS microservices architecture?

A SaaS microservices architecture is a way of building a software-as-a-service product as a set of small, independent services instead of one large application. Each service owns one part of the product, such as billing, user accounts or notifications, and talks to the others through defined interfaces.

The services usually run as separate processes and deploy on their own schedules, so a team can change billing without redeploying the whole product. They share data only through APIs or events, never by reading each other's databases directly. That rule is what keeps the services independent in practice, not just on a diagram.

ServiceOwnsTalks to
IdentityUsers, roles, loginEvery other service
BillingPlans, invoices, paymentsIdentity, core product
Core productThe main featuresBilling, notifications
NotificationsEmail, in-app messagesCore product, billing
ReportingUsage, dashboardsCore product, billing

This shape fits SaaS products that change often and serve many customers, because teams can work on one service at a time. It is a poor fit for a small product with one team, where the extra moving parts cost more than they save. A microservices design earns its keep only when the product is big enough to need it.

How do you draw service boundaries for a SaaS product?

You draw service boundaries around business capabilities, not around database tables or code folders. A good boundary follows a part of the product that changes for its own reasons, such as billing rules, user management or the core feature set.

Start with the product's main nouns: the account, the subscription, the project, the invoice, the report. Each noun that has its own rules and its own lifecycle is a candidate service. If two nouns always change together, they probably belong in one service, not two.

Test each boundary with a question: can this service deploy, scale and fail without taking the others down? If the answer is no, the boundary is wrong or the services are still sharing too much. Shared libraries for common code are fine; a shared database is not, because it turns separate services back into one system.

Keep the count small at first. Three to six services cover most early SaaS products, and each new service adds deployment, monitoring and debugging work. The microservices architecture patterns that work best for SaaS are the simple ones: an API gateway in front, events between services, and one database per service.

How do tenants share services without sharing data?

Tenants share services in a SaaS product by running on the same code and infrastructure while keeping their data strictly separate. Every request carries a tenant identifier, and every service checks it before reading or writing anything.

There are three common patterns. In a shared database with a tenant column, all tenants live in the same tables and every query filters by tenant. In a schema-per-tenant model, each tenant gets its own schema inside one database. In a database-per-tenant model, each tenant gets a fully separate database.

The shared-database pattern is cheapest and simplest to operate, but one bad query can expose another tenant's data, so the tenant filter must be tested hard. The database-per-tenant pattern is the safest and the easiest to move or delete a tenant, but it costs more to run and to back up. Most SaaS products start shared and move their largest or most regulated tenants to separate databases later.

Whatever pattern you pick, make tenant isolation a rule the code enforces, not a habit developers remember. A SaaS tech stack should include automated tests that try to read one tenant's data as another tenant and fail the build if they succeed.

What holds the services together?

An API gateway, shared contracts and events hold a SaaS microservices system together. The gateway is the single front door: it handles login, rate limits and routing, so each service behind it can stay simple and focused on its own job.

Contracts matter more than code. Each service publishes an API contract that says what it accepts and returns, and it keeps that contract stable even as its internals change. When a contract must change, the service ships a new version and keeps the old one running until every caller has moved.

Events carry changes between services without tight coupling. When billing creates an invoice, it publishes an event, and the reporting service picks it up in its own time. If reporting is down, the event waits in a queue instead of breaking the invoice flow. This pattern also gives you an audit trail for free, since every important change is an event on the record.

Keep the number of cross-service calls low. A request that hops through five services to answer one question will be slow and hard to debug. Design so that most requests touch one or two services, and let the rest catch up through events.

How do you deploy and run it without a big ops team?

You deploy a SaaS microservices system by automating everything a human would otherwise do by hand: building, testing, deploying, watching and rolling back. Each service gets its own pipeline, so a change to notifications cannot block a billing release.

A workable setup has five parts:

  1. One pipeline per service. Build, test and deploy each service on its own, with its own version number.
  2. Containers and a scheduler. Package each service the same way and let the platform place and restart it.
  3. Central logging and tracing. Every request gets an ID that follows it across services, so one failure can be traced end to end.
  4. Health checks and alerts. Each service reports whether it is healthy, and the team is paged only when users are affected.
  5. Automated rollback. A bad deploy returns to the previous version in minutes, not hours.

Start with one shared staging environment that mirrors production, and add per-service test environments only when teams start blocking each other. A partner for SaaS development can set up the pipelines and observability, but the team that owns each service should own its alerts too.

Example (hypothetical): splitting a billing SaaS into services

Example (hypothetical): a team runs a billing SaaS for small firms as one application with 40,000 lines of code. Deploying a fix takes 90 minutes, and a bug in reporting once took billing offline for 3 hours.

The team splits the product into five services: identity, billing, core product, notifications and reporting. Each service gets its own database and its own pipeline. A deploy now takes 12 minutes per service, and the five services together deploy in about an hour when all of them change, which rarely happens in one week.

In the first month after the split, the team ships 14 releases across the five services, against 4 releases in the month before. Reporting goes down once for 40 minutes, but billing and the core product keep running, so no customer loses the ability to invoice.

The cost is real too: the team now runs 5 databases instead of 1, and debugging a failed invoice means checking traces across 3 services. The split paid off because the team had 8 engineers and a product that changed weekly, not because microservices are right for every SaaS product.

What are the common mistakes?

The most common mistakes in SaaS microservices projects are splitting too early, drawing boundaries around teams instead of capabilities, and treating the network as free.

  • Splitting a small product. A three-person team with one product gains nothing from five services and pays for five deployments, five databases and five sets of alerts.
  • Boundaries by team, not by domain. Services that mirror the org chart change whenever the team changes, and they share data because the teams talk more than the services do.
  • One shared database. Services that read each other's tables cannot deploy or fail independently, so the architecture is microservices in name only.
  • Chatty services. A page that needs ten calls across five services will be slow, and each call is a new way to fail.
  • No tracing or ownership. When nobody can follow a request across services and nobody owns each service's alerts, outages take far longer to fix.
  • Skipping contract tests. A service that changes its API without warning breaks its callers in production, not in a code review.

Key takeaways

  • A SaaS microservices architecture splits the product into small services that own one capability each
  • Draw boundaries around business capabilities, and keep one database per service
  • Tenant data stays separate through a tenant ID checked on every request
  • An API gateway, stable contracts and events hold the services together
  • Automated pipelines, tracing and rollback make the system operable by a small team

Frequently asked questions

When should a SaaS product move to microservices?

When one team or one deploy is slowing the others down, usually once the product has several distinct capabilities and more than one team working on it. A small product with one team is faster as a single application, and splitting early adds deployment and debugging work without any gain.

How many services should a SaaS product start with?

Three to six is a sensible start. Each service should own one business capability, such as identity, billing or the core product. More services mean more pipelines, databases and alerts, so add a service only when a capability has its own rules and its own release rhythm.

How do microservices handle multi-tenant data?

Every request carries a tenant identifier that each service checks before reading or writing. Tenants can share one database with a tenant column, use a schema per tenant, or get a database each. The separate-database option is safest and easiest to move, but costs more to run.

What is the API gateway for in a SaaS microservices setup?

The gateway is the single front door for all requests. It handles login, rate limits and routing to the right service, so each service behind it stays simple. It also gives you one place to enforce tenant checks and to log every request that enters the system.

Do microservices make a SaaS product more reliable?

They can, because one service can fail without taking the others down, and a bad deploy can be rolled back service by service. But they also add failure modes, such as network calls between services, so reliability depends on tracing, health checks and automated rollback being in place.

What is the biggest cost of microservices for a SaaS team?

Operations. Each service needs its own pipeline, database, monitoring and alerts, and debugging a request means following it across several services. Teams often underestimate this cost, which is why starting with a single application and splitting later is usually the cheaper path.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: software products in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Building a SaaS product and deciding how to structure it? Talk to Hertiv.

A senior engineer replies within one business day. Or see our SaaS Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call