Microservices Architecture and Service Decomposition Questions
Decomposing a system into services along bounded contexts, defining service boundaries and ownership, and managing the tradeoffs against a monolith. Covers cohesion, coupling, data ownership per service, the distributed-monolith anti-pattern, and when a modular monolith beats microservices. Emphasizes decomposition reasoning rather than any single framework.
Describe the step-by-step process to extract one backend module from a monolith into an independently deployable microservice in production. Address data ownership and migration, keeping API compatibility for existing callers, your testing strategy (unit, integration, canary), deployment sequencing (including a routing layer or feature toggle to shift traffic), and how you would roll back safely if something goes wrong.
Sample Answer
Direct answer
Extracting one backend module into an independently deployable service, in production, follows this sequence: define the new service's API contract first, stand it up against a copy or a read path into the existing data, migrate data ownership deliberately (not as an afterthought), route traffic gradually with the ability to roll back, and verify with a layered testing strategy (unit, integration, and canary) at each step before fully committing.
Structured elaboration
Data ownership and migration: decide upfront whether the new service will own its data from day one (with the monolith's data migrated or backfilled into it) or will read through to the monolith's database temporarily via an anti-corruption layer while a migration happens in the background; the second is lower-risk but requires a clear plan (and a deadline) for when the temporary dependency gets removed. API compatibility: the new service's external contract needs to match what existing callers expect, at least at first, so that extracting the implementation doesn't require every caller to change simultaneously; if the contract does need to differ, put a thin compatibility-shim in front of it rather than forcing a synchronized multi-team cutover. Testing strategy: unit tests validate the new service's own logic in isolation; integration tests validate its actual contract against real (or realistic) callers and dependencies; canary deployment routes a small percentage of production traffic to the new service while the rest still goes to the monolith's original code path, letting you compare real production behavior (error rates, latency, and, where possible, output correctness) before committing further. Deployment sequencing: stand up the new service dark first (deployed, but receiving no real traffic), then canary a small percentage, then ramp up gradually while watching the comparison metrics, only fully cutting over once the canary period has run long enough to build confidence. Rollback: keep the old code path in the monolith intact and routable-to until the new service has been fully cut over and stable for a defined period, since the fastest, safest rollback is simply routing traffic back to code that's still there and known to work.
Worked example
For extracting an Orders module using the strangler pattern specifically: put a routing layer in front of the order-related endpoints, implement the new Orders service, and use a feature toggle to control what percentage of order-related traffic each order type or user segment routes to; start with a low-risk subset (say, read-only order-status lookups) before migrating writes, since write-path bugs in a payments-adjacent flow are far more costly to get wrong than a stale read. Data migration in this case might use change-data-capture (CDC), streaming the monolith's writes to the new service without a two-way dependency, to backfill the new service's database, with a reconciliation job comparing the two periodically until the migration is confirmed complete and the CDC feed can be turned off.
Trade-offs and pitfalls
A minimal-viable extraction still needs to cover: the API contract (don't skip this even for a "small" extraction, since an undocumented implicit contract is exactly what breaks callers later), the data-ownership plan (explicit, not "we'll figure it out"), monitoring and observability on the new service from day one (not added after the first incident), and, critically, a genuine rollback path, not just a plan that assumes the cutover will go smoothly. The most common corner cut under time pressure is skipping the canary phase and cutting over 100% of traffic at once; canarying costs a bit more calendar time but catches the class of bug that only shows up under real production load and real data shapes, which unit and integration tests, however thorough, tend to miss.
Analyze the trade-offs between a shared database accessed by many services and a database-per-service pattern. Cover cross-service joins, distributed transactions, reporting/analytics access, data duplication, and eventual consistency on the database-per-service side, and cross-team coupling on schema changes, deployments, and failure isolation on the shared-database side.
Sample Answer
Direct answer
A shared database accessed by many services is operationally simple (one place to back up, one place to query for a report, easy cross-table joins) but structurally couples every service that touches it: a schema change by one team can silently break another team's queries, and there's no way to enforce that only one service writes a given piece of data. Database-per-service removes that coupling, giving each service full control over its own schema and enforcing that it's the only writer of its data, at the cost of needing an explicit strategy for anything that used to be a simple SQL join across tables now owned by different services.
Structured elaboration
With a shared database: cross-service joins are trivial (a single SQL query spanning tables owned by different logical services), transactions across what should be service boundaries are easy (a single atomic, consistent, isolated, durable (ACID) transaction updating two tables), and reporting/analytics can query the whole dataset directly without needing to assemble it from multiple sources. The cost is that these are exactly the things that make it hard to deploy services independently: a schema migration has to consider every service that touches the affected tables, not just the service that conceptually owns them, and there's no enforced boundary preventing one service from reaching into data it doesn't really own.
With database-per-service: each service's schema can evolve on its own release schedule, because no other service can be broken by a change to tables it never had direct access to. The costs show up wherever data used to be joined or transacted across what are now separate services: a query that used to be one SQL join becomes either a replicated read model, an API composition call, or a purpose-built reporting/analytics pipeline that consolidates data from every service (commonly by consuming each service's event stream into a data warehouse); a transaction that used to be a single ACID commit across two tables becomes a saga or another cross-service coordination pattern, accepting eventual consistency where strict atomicity used to be free; and data duplication becomes a deliberate, managed trade-off (a service caching a read-only copy of data it needs from another service) rather than an accident.
Worked example
For reporting and analytics specifically, database-per-service usually means building a separate analytical store (a warehouse or lake) fed by each service's change-data-capture stream or event log, rather than pointing a business-intelligence (BI) tool directly at production service databases; this avoids both the tight coupling of shared production tables and the load a heavy analytical query would otherwise put on a service's transactional database. The operational implications differ sharply by pattern: with a shared database, one team's bad migration or one runaway analytical query can degrade every service at once (a single failure domain); with database-per-service, a failure or slow query in one service's database is isolated to that service, at the cost of needing per-service backup, monitoring, and on-call rather than one shared setup.
Describe the modular monolith architectural pattern as an intermediate step before adopting microservices. What are its benefits and drawbacks, and what technical and organizational decision criteria would lead you to recommend staying with a modular monolith versus moving to microservices?
Sample Answer
Direct answer
A modular monolith is a single deployable application whose internal code is organized into strictly-separated modules, each owning its own data and exposing a defined interface to the others, the same discipline microservices apply at the network boundary but enforced inside one process instead of across services. It buys most of the maintainability and clear-ownership benefits people associate with microservices (an engineer can reason about one module without understanding the whole codebase) while keeping the deployment, testing, and debugging story of a single application.
Structured elaboration
The main benefits are: one deploy pipeline and one set of infrastructure to operate, no network calls (and their associated latency and failure modes) between modules that used to be function calls, easier cross-module refactors (the compiler or a single test suite catches a broken contract immediately, instead of it surfacing later as a runtime failure between two independently-deployed services), and a natural stepping stone toward microservices if a specific module's traffic or ownership needs later diverge from the rest.
The main drawbacks are: the module boundaries are enforced by discipline and code review, not by a hard network boundary, so they erode more easily under schedule pressure than a boundary that would require actually calling a different service to violate; every module still shares the same deploy (so a bug in one module can still take down the process serving all of them, and a slow test suite in one module still blocks everyone's release); and a module can't scale independently of the others without scaling the whole process.
Worked example
Decision criteria for staying with a modular monolith rather than moving to microservices: the team is small enough that a shared deploy pipeline isn't a bottleneck, no single module has a materially different scaling profile from the rest, and the org values the lower operational overhead (fewer things to monitor, deploy, and keep backward-compatible) more than independent per-module deployability. The Shopify engineering team's widely-discussed decision to run a modular monolith at very large scale is a well-known real-world example: strict internal module boundaries with a shared deployable, extracting specific components to their own services only when a concrete scaling or ownership need justified it.
Trade-offs and pitfalls
The most common failure mode is treating "modular monolith" as a label rather than a discipline: without enforced module boundaries (linting rules, code-ownership checks, or architectural review that catches a module reaching directly into another module's tables), a modular monolith degrades back into an ordinary tangled monolith over time, at which point it has neither the deployability benefits of microservices nor the simplicity benefits of a genuinely modular codebase.
Explain the strangler fig pattern for migrating a monolith to microservices: the role of a routing/intercept layer, the role of anti-corruption layers when the new service must still talk to the old monolith's data, and how you would manage shared-database access during the transition period. Describe how you'd prioritize which components to extract first.
Sample Answer
Direct answer
The strangler fig pattern migrates a monolith to microservices incrementally: you place a routing layer in front of the monolith, redirect one slice of functionality at a time to a newly-built service behind that layer, and let the monolith's role shrink slice by slice until, eventually, it can be retired, rather than attempting a single big-bang rewrite.
Structured elaboration
The routing (or intercept) layer is the mechanism that makes this incremental: it sits in front of the monolith and inspects each incoming request, forwarding requests for the not-yet-migrated functionality to the monolith as before, and requests for the newly-extracted slice to the new service instead. Because the routing decision happens per-request, the cutover for any one slice can be gradual (a percentage of traffic, or a specific subset of users) and reversible (route back to the monolith if the new service misbehaves), rather than an all-at-once switch.
An anti-corruption layer handles the case where the new service still needs to talk to the old monolith, either because the monolith still owns some data the new service needs, or because other parts of the monolith still call into the functionality that's now been extracted. Rather than letting the new service's clean domain model get contaminated by the monolith's legacy data shapes and conventions, the anti-corruption layer translates between the two, so the new service's internal model stays coherent even while it's still dependent on the old system underneath.
Managing shared database access during migration is the trickiest part: in the transition window, both the monolith and the new service may need to read or write data that hasn't fully moved yet. A common approach is dual-write (the monolith continues writing to its tables while also publishing changes the new service consumes) with reconciliation to catch drift, or a change-data-capture stream from the monolith's database that the new service consumes without writing to the monolith's tables directly, avoiding a genuine two-way dependency on the same schema.
Worked example
Prioritizing which components to extract first: start with a slice that's relatively self-contained (few dependencies on the rest of the monolith), has a clear owning team ready to take it on, and delivers a visible win (either operational, like removing a frequent source of incidents, or business, like unblocking a team that's currently release-blocked by the monolith's shared deploy train). Extracting the riskiest, most deeply-entangled part of the monolith first, even if it's the part causing the most pain, tends to produce the highest-risk first migration when the team has the least experience running this pattern; a smaller early win builds the operational muscle (routing, dual-write, monitoring the new service) that the harder extractions will need later.
Trade-offs and pitfalls
The most common failure is leaving the routing layer and the dual-write/reconciliation logic in place indefinitely instead of treating them as temporary migration scaffolding; if a slice never gets fully cut over (the monolith keeps a code path alive "just in case"), the system ends up permanently carrying the complexity of both the old and new implementations, which is worse than either the original monolith or a clean microservice on its own.
A user-profile subsystem for a global application needs to serve a large, latency-sensitive user base. Describe how you would decompose responsibilities across services (for example profile storage, authentication, preferences, avatar/media processing): where you'd draw the boundaries, whether each inter-service call should be synchronous or asynchronous, how you'd isolate one service's failures from the others, and how the owning teams should coordinate their APIs and contracts.
Sample Answer
Direct answer
For a global, latency-sensitive user-profile subsystem, a reasonable decomposition splits Profile Storage, Authentication, Preferences, and Avatar/Media Processing into separate services, each with a clearly different access pattern and failure-isolation need, communicating synchronously only where a request genuinely can't proceed without an immediate answer.
Structured elaboration
Authentication is kept separate because it's a security-sensitive, extremely high-frequency, low-latency dependency that nearly every other request needs to check, and isolating it means an issue in less-critical functionality (like avatar processing) can never take down the ability to authenticate a request. Profile Storage owns the core profile fields (name, settings, account state) and needs to be read on nearly every request, so it's optimized for fast, simple reads, kept narrowly scoped to just that core data rather than accumulating every profile-adjacent feature over time. Preferences (notification settings, UI preferences, and similar lower-stakes, less frequently-read data) is split out specifically because it doesn't need the same latency or availability guarantees as core profile and authentication data; if the Preferences service is slow or briefly unavailable, the rest of the profile experience should still work with sensible defaults, whereas Authentication being unavailable is a much more serious failure. Avatar/media processing is naturally asynchronous (resizing, transcoding, or moderating an uploaded image takes real time and doesn't need to block the rest of the profile experience) and has a very different resource profile (CPU/IO-heavy batch-style work) from the fast, simple reads the other services handle, making it a clear candidate for its own service with its own scaling behavior.
On communication choices: reading a user's core profile (needed on most page loads) should be synchronous, since the caller can't meaningfully proceed without it; updating a display avatar can be asynchronous, since the caller doesn't need to wait for image processing to finish, just for the upload to be accepted. Failure isolation follows from the split: if Avatar Processing is degraded, users can still authenticate, read their profile, and use the rest of the product, with a graceful fallback (a default avatar, or the previous one) rather than the whole profile experience failing.
Worked example
For team coordination across these services: the team owning Authentication needs the strictest change-management discipline given its security sensitivity and blast radius if it breaks, and its API contract with the other three services should be the most stable and carefully versioned of the four; Profile Storage's API needs to stay backward-compatible for the many other services and clients that read from it directly; Preferences and Avatar Processing, being lower-stakes and more independently used, can iterate faster with a lighter review process, as long as their optional, non-blocking nature is preserved (nothing else should come to depend on them synchronously in a way that would undo the isolation benefit).
Trade-offs and pitfalls
The most common mistake in a decomposition like this is letting Profile Storage's scope creep to absorb Preferences or other adjacent data over time ("it's just one more field"), which quietly recreates the coupling the split was meant to avoid; keeping the boundary honest requires treating a new field's home as a deliberate decision (does this need Profile Storage's stricter availability and latency guarantees, or can it live in the more relaxed Preferences service) rather than defaulting to wherever's most convenient to add it.
Unlock Full Question Bank
Get access to all 34 Microservices Architecture and Service Decomposition interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.