Choosing an architecture, part 2 of 2 (series complete)
Microservices, when the need is real
Microservices pay off when teams need to ship on their own. How to tell the need is real, move a module out without stopping delivery, and make services pay.
Bhanu Chhabra, . 15 minute read
The previous article, Start with a modular monolith, argued that most new projects should begin as one deployable with enforced boundaries inside it. Sooner or later, some of them outgrow it, and what usually outgrows it first is the number of teams trying to release it.
What microservices are for
James Lewis and Martin Fowler described microservices as a suite of independently deployable services, built around business capabilities [1]. Each service runs in its own process, owns its data and ships on its own schedule.
A service can scale on its own, fail without taking the rest down, and use the runtime it needs. For most organisations, though, the benefit that matters is independent delivery: a team can change its part of the system and release it without waiting for anyone else.
That’s why the case for microservices usually starts with people. Melvin Conway observed in 1968 that a system’s design ends up copying the communication structure of the organisation that builds it [2]. With one team, that pull works for you: one team, one deployable. With eight teams sharing one deployable, every release becomes a negotiation. Services let the architecture match the teams, so each team owns a part of the system it can change and release alone.
Fowler also lists what it costs: calls go over a network and can fail, consistency becomes eventual, and there are many more things to deploy and run [3]. Microservices are worth it when the gain in independent delivery is bigger than that cost.
How to tell the need is real
Look for these signs, and measure them where you can:
- Teams wait on each other to release. There’s a release train, a merge queue, or a meeting to agree what goes out this week.
- Lead time grows as you add people. More engineers make delivery slower, because they all change and test the same deployable.
- One capability has a different load or failure profile. It needs to scale on its own, or its incidents keep spreading to everything else.
- A part needs separate rules. A different runtime, or isolation for compliance, audit or data residency.
The DORA metrics are a good way to measure the first two. Lead time for changes and deployment frequency show how fast work gets out; change fail rate and recovery time show whether it stays up [4]. If lead time climbs and deploys slow down as teams join, and the waiting happens around the shared deployable, you have evidence. Write the need down with a number, split, and measure again. If the team’s deployment frequency doesn’t rise, or the incidents keep spreading, the split didn’t pay for itself.
The prerequisites from the previous article still apply: stable boundaries, automated delivery per service, observability across services, clear ownership, contract discipline and the skills to handle distributed data. A real need without them gives you microservices you can’t run well.
Microservices and micro-frontends: one team, one slice
Many organisations stop halfway. The backend is split into services, but the frontend is still one application, owned by a frontend team or shared by everyone. Services deploy on their own, yet almost every feature ends in the same frontend codebase and the same release. The bottleneck has moved from the backend to the UI, and teams are coordinating again.
Micro-frontends take the same idea to the UI. Cam Jackson defines them as independently deliverable frontend applications composed into a greater whole, and he names independent deployment as the key property, just as it is for microservices [5].
Put the two together and a team can own a vertical slice of the product: its screens, its API, its data, its pipeline and its on-call. Team Topologies calls this a stream-aligned team, one that delivers a stream of work without handing parts of it to other teams [6]. It’s also what Werner Vogels described at Amazon in 2006: you build it, you run it [7].
Teams by layer
3 teams, 2 hand-offs, 3 waits in a queue
Teams by slice
1 team, no hand-offs
In practice, a slice team owns:
| Part of the slice | What the team owns |
|---|---|
| Screens | Its micro-frontend: pages or fragments, built and deployed on its own |
| API | Its services, plus a backend for its frontend where the UI needs a tailored API [8] |
| Data | Its own database. Other teams get the data through the team’s API or events |
| Delivery | Its pipeline, feature flags and release schedule |
| Running it | Dashboards, alerts and on-call for everything above |
Putting the frontend together
The micro-frontends still have to look and behave like one product. A few choices make that work:
- An app shell. A thin host owns the page layout, routing, sign-in and navigation, and loads each team’s micro-frontend into it.
- Run-time composition. Jackson compares server-side composition, build-time integration and run-time integration [5]. Building everything together from packages brings lockstep releases back, so prefer composing at run time: Module Federation, web components, or server-side includes for mostly static pages.
- A shared design system. One set of components and tokens keeps the slices looking the same. It’s a dependency every team uses, so version it carefully and keep business logic out of it.
- Loose communication. Micro-frontends talk through the URL and through browser events. Shared global state between them couples the teams again.
In an Angular shell with Module Federation, two decisions carry most of the weight. The first is what’s shared. Angular and RxJS are loaded once, as singletons, and a remote built against a different major version fails at load time instead of misbehaving at run time [15]:
// webpack.config.js, in the shell and every remote
const { shareAll, withModuleFederationPlugin } = require('@angular-architects/module-federation/webpack');
module.exports = withModuleFederationPlugin({
shared: {
...shareAll({ singleton: true, strictVersion: true, requiredVersion: 'auto' }),
},
});
The cost of that is version skew: a framework upgrade is now coordinated across every team, much like the lockstep upgrade in a monolith, only spread across repositories. Plan it as a programme, with a window in which remotes can move.
The second is what happens when a remote doesn’t load. The shell reads remote locations from a manifest at start-up, so teams deploy without rebuilding it, and every remote route has a fallback. One team’s bad deploy then shows a message on its own pages instead of a blank screen for the whole product:
// shell routes: remote locations come from a manifest fetched at start-up
export const routes = (manifest: RemoteManifest): Routes => [
{
path: 'billing',
loadChildren: () =>
loadRemoteModule({ type: 'module', remoteEntry: manifest.billing, exposedModule: './routes' })
.then((m) => m.BILLING_ROUTES)
.catch(() => unavailableRoutes('Billing')), // this slice is down; the rest still works
},
];
Watch the other costs as well: duplicated libraries in the browser when sharing is misconfigured, uneven look and feel when teams drift, and more pipelines to keep healthy.
Moving from a modular monolith, one module at a time
If the monolith was built the way the previous article described, the hard part is already done. Each module owns its data and talks through a contract, so extracting one is a series of small changes, each released on its own.
Pick the first module carefully: one with a need you’ve written down, few dependencies on other modules, and a contract that’s been stable for a while. In the previous article that was Billing.
- Keep the contract, and check it’s the only way in. Callers already use
IBillingModule. This is branch by abstraction: making a large change gradually while you keep releasing [9]. Before anything moves, look for what crosses the boundary today and won’t survive a network: a transaction that commits an order and its invoice together, a report that joins into Billing’s tables, a caller that assumes Billing answers in microseconds. Each one becomes an event, an API call or a read model first. - Build the service behind the same contract. Deploy the Billing service and add a second
implementation of
IBillingModulethat calls it over the network. It gets no traffic yet. The new hop needs what an in-process call never did: service-to-service authentication, the tenant and trace context passed on every call, and a timeout that’s yours rather than the default. - Shift reads gradually. A flag routes a small share of reads to the service, then more, comparing the two sides before you trust the new one. For traffic that comes from outside, route it at the gateway, as in the strangler fig pattern [10].
- Move the data, then the writes. Billing’s schema is already its own. Backfill it into the service’s database, then keep it current with change data capture from the monolith’s tables while both sides run. Avoid writing to both databases from application code: when one write succeeds and the other fails, nothing tells you. Run a reconciliation job, per tenant, until it comes back clean. Then switch writes tenant by tenant, and keep the sync running in reverse for as long as you want a way back. From here the service publishes Billing’s events through its own transactional outbox [11].
- Clean up. Delete the router, the in-process implementation, the sync and the flag. Callers still use the same interface.
The second implementation is small. It calls the service over HTTP behind the same contract:
// Same contract, new implementation: calls the Billing service over HTTP
internal sealed class BillingServiceClient(HttpClient http) : IBillingModule
{
public async Task<InvoiceSummary> GetInvoiceAsync(Guid invoiceId, CancellationToken ct) =>
await http.GetFromJsonAsync<InvoiceSummary>($"invoices/{invoiceId}", ct)
?? throw new InvoiceNotFoundException(invoiceId);
}
The routing is where the flag comes in. A plain on/off flag only says which side serves a call. A migration needs more than that, so the flag here is a string with four stages, the same ones LaunchDarkly uses for its migration flags [12]:
| Stage | Who answers | Also called, to compare |
|---|---|---|
off |
Monolith | Nothing |
shadow |
Monolith | Service |
live |
Service | Monolith |
complete |
Service | Nothing |
The router asks LaunchDarkly for the stage on every call and does what it says. It doesn’t decide anything itself, and it never makes the caller wait for the comparison:
internal static class FlagKeys
{
public const string BillingExtraction = "billing-extraction";
}
// Registered as IBillingModule while Billing moves. LaunchDarkly picks the stage per tenant;
// the router only carries it out. Reads only: writes move separately (step 4).
internal sealed class BillingRouter(
ILdClient flags, ITenantContext tenant, BillingModule monolith,
BillingServiceClient service, ShadowComparer comparer) : IBillingModule
{
public async Task<InvoiceSummary> GetInvoiceAsync(Guid invoiceId, CancellationToken ct)
{
var context = Context.Builder(ContextKind.Of("tenant"), tenant.Id)
.Set("region", tenant.Region)
.Set("plan", tenant.Plan)
.Build();
// If LaunchDarkly can't be reached, the fallback keeps every call in the monolith
var (answers, check) = Route(flags.StringVariation(FlagKeys.BillingExtraction, context, "off"));
var result = await answers.GetInvoiceAsync(invoiceId, ct);
// The check happens after the caller has its answer, off the request path
if (check is not null)
comparer.Enqueue(new ShadowCheck(invoiceId, tenant.Id, result, check.GetType()));
return result;
}
private (IBillingModule Answers, IBillingModule? Check) Route(string stage) => stage switch
{
"shadow" => (monolith, service),
"live" => (service, monolith),
"complete" => (service, null),
_ => (monolith, null),
};
}
The comparison runs in the background. It’s bounded, so a slow side can’t pile up work: when the
queue is full, new checks are dropped, never the caller’s request. And it gets its own scope,
because the request’s DbContext is gone by the time the check runs:
internal sealed record ShadowCheck(Guid InvoiceId, string TenantId, InvoiceSummary Expected, Type Side);
internal sealed class ShadowComparer(IServiceScopeFactory scopes, ILogger<ShadowComparer> log)
: BackgroundService
{
private readonly Channel<ShadowCheck> _queue = Channel.CreateBounded<ShadowCheck>(
new BoundedChannelOptions(1_000) { FullMode = BoundedChannelFullMode.DropWrite });
public void Enqueue(ShadowCheck check) => _queue.Writer.TryWrite(check);
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await foreach (var c in _queue.Reader.ReadAllAsync(stoppingToken))
{
await using var scope = scopes.CreateAsyncScope();
scope.ServiceProvider.GetRequiredService<ITenantContext>().Use(c.TenantId);
var side = (IBillingModule)scope.ServiceProvider.GetRequiredService(c.Side);
using var timeout = CancellationTokenSource.CreateLinkedTokenSource(stoppingToken);
timeout.CancelAfter(TimeSpan.FromSeconds(2));
try
{
// InvoiceSummary is a record, so != compares values
if (await side.GetInvoiceAsync(c.InvoiceId, timeout.Token) != c.Expected)
log.LogWarning("Billing mismatch for {InvoiceId}, tenant {TenantId}", c.InvoiceId, c.TenantId);
}
catch (Exception ex) when (!stoppingToken.IsCancellationRequested)
{
// The side being checked must never affect anything but this log
log.LogWarning(ex, "Billing check failed for {InvoiceId}, tenant {TenantId}", c.InvoiceId, c.TenantId);
}
}
}
}
Shadowing doubles the reads on whichever side is being checked, so roll the shadow out by percentage too, and watch both databases while it runs.
Because the context carries the tenant, its region and its plan, the redirect strategy lives in LaunchDarkly’s targeting rules, not in the code. Rules are checked from the top, and the first match wins. A typical sequence:
- Shadow everyone. The default rule serves
shadow. Real traffic exercises the service while the monolith still answers, and the mismatch log tells you what the tests missed. - Your own tenants first. A rule for an
internal-tenantssegment serveslive, so your own staff see the service’s answers before any customer does. - Low-risk cohorts next. A rule such as
plan is freeorregion is apacserveslive, wherever a mistake is cheapest to make and easiest to explain. - Then a percentage. The default rule becomes a rollout: 5%
liveand 95%shadow, then 25%, 50% and 100%. LaunchDarkly buckets by the context key, so a tenant stays on the same side from one call to the next. - A way back. If errors climb, set the default rule back to
shadow. It takes effect in seconds, with no deploy.
The router handles reads. Writes are different: shadowing a command runs it twice, and two
invoices or two emails aren’t a mismatch you can log and move on from. Writes stay on the
authoritative side while the data syncs, and move only once reads have been live for a while
(step 4). LaunchDarkly’s six-stage migration flags add dualwrite and rampdown stages for
exactly this case, when reads and writes need to move separately [12].
Complete: the router, the in-process module and the sync are deleted, and the flag is archived. Callers still use IBillingModule.
Once every rule serves complete and the mismatch log has been quiet for a while, the router has
done its job. Delete it, along with the in-process BillingModule, its tables and the sync, and
register the client as the only implementation:
// During the move: both sides, the router for callers, the comparer in the background
services.AddScoped<BillingModule>();
services.AddHttpClient<BillingServiceClient>(http => http.BaseAddress = new Uri("https://billing.internal/"))
.AddHttpMessageHandler<ServiceTokenHandler>() // service-to-service authentication
.AddStandardResilienceHandler(); // timeouts, retries and a circuit breaker
services.AddSingleton<ShadowComparer>();
services.AddHostedService(sp => sp.GetRequiredService<ShadowComparer>());
services.AddScoped<IBillingModule, BillingRouter>();
// After: one implementation, and no router, comparer or flag
services.AddHttpClient<IBillingModule, BillingServiceClient>(http => http.BaseAddress = new Uri("https://billing.internal/"))
.AddHttpMessageHandler<ServiceTokenHandler>()
.AddStandardResilienceHandler();
Don’t leave the resilience handler out. Without it, a typed HttpClient waits 100
seconds before giving up, which is how one slow service ties up the threads of everything that
calls it. The standard handler from Microsoft.Extensions.Http.Resilience adds a rate limiter,
an overall timeout, retries, a circuit breaker and a per-attempt timeout [14].
Then archive the flag in LaunchDarkly. Code references show where a flag key still appears in your repositories, so you can confirm nothing reads it before it goes [13]. A migration flag left in place after the move is the kind of dead branch that confuses the next person to read the code.
Patterns that make services pay off
Once you have more than a couple of services, a small set of patterns does most of the work:
| Pattern | Use it for | Watch out for |
|---|---|---|
| Database per service | Letting each service change its data without asking anyone | Questions that span services need an API call or a read model, not a join |
| Transactional outbox [11] | Publishing an event reliably with the database write that caused it | Consumers must handle duplicates, so make them idempotent |
| Saga | A business process that spans services, such as order, payment and shipping | Compensating steps are business rules; design them with the product owner |
| Events over call chains | Anything that doesn’t need an immediate answer | The UI has to show “processing” states honestly |
| Backend for frontend [8] | One API per client experience, owned by the team that owns that UI | Shared logic creeping into every BFF; push it down into services |
| Timeouts, retries, circuit breakers | Keeping one slow service from taking others down | Retries without idempotency repeat work |
| Consumer-driven contract tests | Changing an API without breaking the teams that use it | Both teams have to run them in CI |
| Distributed tracing | Following one request across every service it touches | It only works if every service passes the trace context on |
How to get the most out of microservices
Give teams the whole slice
Microservices pay off when a team can take a change from idea to production and then run it. Split the work by layer and you keep the hand-offs while paying the network cost.
Make a new service cheap
A platform team that provides templates, pipelines, logging, tracing and alerting out of the box lets stream-aligned teams spend their time on the product [6]. If starting a service takes a sprint of setup, teams will avoid splitting where they should, or skip the setup and run services nobody can see into.
Size services to a team
A service should be small enough for one team to own and large enough that most changes stay inside it. Two services that always change together should be merged.
Avoid the distributed monolith
The warning signs are services that have to be deployed together, a database shared between services, shared libraries that carry business logic, and long chains of synchronous calls to answer one request. Each one brings back the coordination you split to escape.
Keep measuring
Track the DORA numbers per team before and after each split [4]. They tell you whether the architecture is helping delivery, and where it isn’t.
Wrapping up
Start with a modular monolith, and move a module out when a team or a capability needs to ship, scale or fail on its own. Pair the services with micro-frontends so each team owns its slice from the screen to the database. Make each move in small steps that can be released and rolled back, and check the DORA numbers afterwards to see whether the split paid off.
References
- James Lewis and Martin Fowler, Microservices (2014). Back to text
- Melvin E. Conway, How Do Committees Invent?, Datamation (1968). Back to text
- Martin Fowler, Microservice Trade-Offs (2015). Back to text
- Nathen Harvey, DORA, A history of DORA’s software delivery metrics (2026). Back to text
- Cam Jackson, Micro Frontends (2019). Back to text
- Matthew Skelton and Manuel Pais, Team Topologies (IT Revolution, 2019). Back to text
- Jim Gray, A Conversation with Werner Vogels, ACM Queue (2006). Back to text
- Sam Newman, Pattern: Backends For Frontends (2015). Back to text
- Martin Fowler, Branch By Abstraction (2014). Back to text
- Martin Fowler, Strangler Fig (2004, revised 2019). Back to text
- Chris Richardson, Pattern: Transactional outbox, microservices.io. Back to text
- LaunchDarkly, Migration flags, SDK documentation. Back to text
- LaunchDarkly, Code references, product documentation. Back to text
- Microsoft, Build resilient HTTP apps: key development patterns, .NET documentation. Back to text
- Manfred Steyer, Angular Architects, The Microfrontend Revolution: Module Federation with Angular. Back to text