Microservices vs Monolith in the Age of AI and Automation

Nov 19, 2026 | Tech Leadership

Microservices vs Monolith in the Age of AI and Automation

For most businesses adding AI and automation, a well-structured modular monolith is still the right default. Microservices are worth their cost only for the specific components that behave very differently from the rest of your system. AI does not reverse the microservices vs monolith trade-off. It adds three or four new parts that often deserve their own boundary: model inference, agent execution, background workflows and the gateway to external model providers. The practical answer is usually a monolith with a few deliberately extracted services, not a fleet of fifty.

That is a less exciting answer than either camp wants. The rest of this piece explains where the line falls, what changes when large language models enter your system design, and how to move from monolith to microservices one component at a time when you genuinely need to.

Why AI does not flip the old trade-off

The original case for microservices was as much organisational as technical. Independent teams could ship independently, components could scale independently and failures stayed contained. The cost was always operational: network calls where there used to be function calls, distributed transactions, versioned contracts, tracing across services, and a platform team to keep the whole thing running. None of that cost has gone away. A ten-person company running twenty services still pays a coordination tax, and it buys very little in return.

What AI changes is the shape of some workloads. A typical web request finishes in tens of milliseconds and costs a tiny amount of compute. An LLM call can take several seconds and can fail on a provider’s rate limit. It costs real money per token, and its output has to be validated before you trust it. An agent loop might make a dozen of those calls and invoke tools that write to your database or send emails on your behalf. Those are very different runtime characteristics, and different runtime characteristics are the best reason to draw a service boundary.

So the useful question is not whether the whole system should be a monolith or microservices. It is this: which of the new AI components behave so differently that sharing a process with the rest of the application becomes a liability? In most software architecture for AI, the honest answer is a short list.

The four AI components that earn a boundary

The model gateway

Every call to a model provider should pass through one place in your code. That one module handles authentication, retries, timeouts, token budgets, logging of prompts and responses, and the mapping from a task such as “summarise this invoice” to a specific model and version. Model prices and capabilities move month to month. A new release can cut prices or change behaviour overnight, as the GPT-6.2 Astra price cut showed. You want swapping a model to be a configuration change, not a hunt through forty files.

In a small system the gateway is a module inside the monolith, and that is fine. It becomes a separate service in three situations: several applications share it, you need central spend controls across teams, or you run your own models alongside third-party APIs. That last case is where the self-hosted versus API decision starts to shape your architecture rather than just your bill.

Inference you host yourself

If you run models on your own GPUs, that workload should be its own deployable, without much debate. It scales on GPU memory and queue depth rather than CPU and request count. It needs different hardware and it deploys on a different cadence. Its failure modes include running out of memory and loading weights that can take minutes. None of that should be able to take down your customer-facing application. Of everything in this article, this is the clearest case for separation.

Agent execution

An agent that can call tools is code whose next action you do not fully control. That makes isolation a security question as much as a scaling one. The agent should run in a separate process or container with its own credentials, scoped to the minimum set of actions it needs. Its network egress should be restricted and every tool call logged.

Sandboxes are not perfect. The allegations in the California case against OpenAI over agent sandbox escapes are a reminder that you have to test containment, not assume it. Still, an agent running inside your main application process with your main database credentials has no containment at all. Mapping, restricting and auditing data flows is far easier when the agent sits behind a clear, narrow boundary.

Background workflows and automations

Most business automation is asynchronous. A document arrives, gets classified, extracted, checked and routed, and a human approves the edge cases. Those steps belong on a queue with workers, retries and dead-letter handling. They do not belong in a web request that times out after thirty seconds.

The workers can live in the same codebase as your monolith and be deployed as a separate process from the same build. That is the cheapest form of separation available, and it is often all you need. Our own AI agents, for example, have a private chat built on Zulip and ntfy. Message-based communication between components is easier to observe and steer than a web of direct calls.

Monolith, modular monolith or microservices: how they compare for AI work

The comparison below assumes a typical setup: an operational business system, a handful of AI features and one or two engineering teams. Change those assumptions and the weighting shifts.

Concern Unstructured monolith Modular monolith Microservices
Adding a first LLM feature Fast, but model calls tend to scatter across the code Fast, with calls routed through one gateway module Slower: new service, contracts, deployment pipeline
Swapping model or provider Painful if calls are scattered One module and a config change One service, if a gateway exists; otherwise many
Scaling self-hosted inference Poor: GPU and web load share a process Poor unless inference is extracted Good: inference scales on its own
Isolating agents with tool access Weak: shared credentials and memory Moderate: separate worker process possible Strong: own container, credentials, network policy
Debugging a bad AI output Easy to trace, hard to find Easy: one log stream, clear module Hard without distributed tracing and correlated logs
Working with AI coding assistants Workable, but changes sprawl Best: whole change visible, one test run Harder: changes span repos and contracts
Team size it suits One small team, short horizon One to several teams Several teams with clear ownership
Operational overhead Low Low to moderate High: platform, on-call, versioning

The modular monolith wins most rows for most mid-sized companies. Microservices win where workloads or risk profiles really diverge, which is why the sensible end state is a hybrid.

AI coding tools quietly favour the monolith

AI also affects your architecture in a second, less obvious way: it changes who, or what, writes the code. Coding assistants and agents do their best work when they can see the whole change in one repository: the handler, the data model, the test and the migration. They also need to be able to verify it with one test run. A change that spans four services means four repositories, a contract change, a coordinated deployment and an integration environment the agent probably cannot reach. Each of those is a place where a confident but wrong change slips through.

A modular monolith with strict internal boundaries, typed interfaces between modules and a fast test suite is close to the ideal environment for AI-assisted development. If those boundaries are enforced by tooling, such as import rules, module ownership and architecture tests in CI, you get most of the discipline microservices impose without putting a network in the middle. That discipline matters more when code is generated quickly. Weak boundaries plus fast generation is a reliable way to accumulate debt, which is the theme of reducing technical debt with automated systems.

Generation speed cuts both ways. AI tools make the glue code that microservices need cheaper to write: clients, schemas, adapters. They do nothing to reduce the ongoing cost of running those services. Someone still owns the pager, the version matrix and the trace that crosses five hops at three in the morning. Cheaper code does not mean cheaper operations.

From monolith to microservices without a rewrite

If you already have a monolith and AI work is pushing against it, the move is extraction, not migration. Rewrites stall. Extracting one component at a time, behind a stable interface, keeps the business running while the architecture changes underneath it. Integrating LLMs into legacy enterprise systems covers the integration side in more depth. The architectural sequence is fairly consistent.

Start by wrapping every model call in a gateway module. That needs no new deployment and pays for itself the first time you change provider or need to explain a cost spike. Next, move long-running AI work onto a queue with workers deployed as a separate process from the same codebase. After that, isolate agent execution with its own credentials and permissions. That is the step most likely to need a real service boundary, because the reasons are about security rather than performance. Split inference into its own service only if you are self-hosting models. Each step is valuable on its own and reasonably reversible, so you can stop wherever the problem stops.

Before any of this, it helps to know what you are working with. An AI readiness audit of your software architecture answers several questions: where data lives, which integrations are brittle, and whether your logging can tell you why a given output was produced.

Failure modes to avoid

The most common mistake is creating a single “AI service” that everything else calls synchronously. It looks like separation, but it behaves like a distributed monolith. Every feature now depends on a network hop to a component with multi-second latency and a provider’s rate limits, and a slowdown there becomes a slowdown everywhere. Keep AI calls asynchronous wherever the user does not need the answer in the same request.

The second mistake is sharing a database between services. That brings back all the coupling you were trying to escape and adds network latency on top. The third is extracting services before you have tracing. Debugging a wrong answer across three services is miserable unless you can follow the prompt, the retrieved context, the model version and the output under a single correlation ID. This observability gap is one of the quieter reasons AI pilots stall before production.

Split, keep or wait: a short decision checklist

Before you commit to a change in system design, check which of these describes your situation.

  • Split it out now if you self-host models, or if an agent can take actions with real consequences: payments, outbound email, writes to systems of record.
  • Keep it as a module in the monolith if you have one team and one product, and your AI features call external APIs through a single gateway.
  • Buy rather than build the plumbing (queues, workflow engines, observability) when a mature managed option meets your data-residency and GDPR requirements; save custom engineering for the parts specific to your business.
  • Wait if you cannot name the scaling, isolation or ownership problem the split would solve, or if fewer than two teams would own the resulting services.
  • Wait if you do not yet have correlated logging of prompts, context and outputs; build that first, because every later step depends on it.
  • Wait if the AI feature is still a pilot: prove the value inside the monolith before you invest in infrastructure for it.

Where D3X Solutions LABS fits

D3X Solutions LABS is an AI engineering studio in Ireland that builds agents, automation and orchestration systems, and advises teams putting AI into production. When the question is architecture, we start by mapping where AI calls happen today, what data and systems they touch, and what a failure would cost. From there we recommend the smallest set of boundaries that solves the real problem, often a gateway module and a worker queue rather than a new platform. Where a team needs ongoing technical leadership rather than a one-off review, a fractional CTO arrangement for AI projects can cover that gap. If you are weighing a split, or wondering whether your current monolith can carry the AI work on your roadmap, book a free 30-minute call and we will work through it with you.

Frequently Asked Questions

Is a monolith or microservices better for AI applications?

For most businesses, a modular monolith is the better starting point, with a few AI components extracted where they behave differently. Self-hosted inference and agents with tool access are the strongest candidates for their own services. Calls to external model APIs can usually live in a gateway module inside the monolith.

When should you move from a monolith to microservices?

Move when you can name a concrete problem a split would solve: a workload that scales on different hardware, a component that needs security isolation, or separate teams blocked by shared releases. Do it by extracting one component at a time behind a stable interface, not by rewriting the whole system.

Do AI coding assistants work better with monoliths?

Generally, yes. Coding assistants and agents work best when the whole change sits in one repository and can be verified with one test run. A modular monolith with enforced internal boundaries and a fast test suite suits AI-assisted development better than changes spread across several services and contracts.

What is a modular monolith?

A modular monolith is a single deployable application split internally into well-defined modules with explicit interfaces and enforced dependency rules. You get much of the structure of microservices without network calls, distributed transactions or the operational overhead of running many services.

Should LLM calls go in a separate microservice?

Not necessarily. All model calls should go through one gateway that handles retries, timeouts, logging and model selection, but in a small system that can be a module. It becomes a separate service when several applications share it, when you need central spend controls, or when you run self-hosted models alongside APIs.

What is a distributed monolith and why does it matter for AI?

A distributed monolith is a set of services so tightly coupled that they must change and deploy together, so you get the costs of microservices without the benefits. With AI, it often appears as one central AI service that everything calls synchronously, which spreads its latency and provider rate limits across the whole system.

Want this working in your business?

D3X Solutions LABS builds AI agents and automation that pay back fast. Bring one process to a free 30-minute call and we will sketch what automating it would take.

Get in touch

Blog

What We Do

Product

Consumer and enterprise software, built with taste and shipped fast.

Infrastructure

AI agents, automation, and orchestration - production systems, not demos.

Advisory

Hands-on engineering and strategy for teams shipping AI into production.