Interviewers ask this to see whether you understand the trade-off honestly, not to catch you out. A shared database across services is generally considered an anti-pattern in microservices, but there are real reasons teams end up with it. Explain the reason, the risks you were aware of, and how you mitigated them. Common legitimate reasons - Incremental migration from a monolith: services were extracted from a monolith gradually (strangler pattern), and splitting a large, highly relational database at the same time was too risky. The plan was to separate data later. - Strong consistency requirements: some workflows needed ACID transactions across what became separate services, and the team was not ready to implement sagas and eventual consistency. - Reporting needs: business reports joined data across domains, and a shared database made reporting simple before a data warehouse existed. - Team size and cost: a small team running several deployable services, where separate database servers and synchronisation pipelines would add significant operational cost. - Time-to-market pressure and existing skills. Risks you should acknowledge - Tight coupling: a schema change by one service can break others, so services cannot deploy independently. - No clear data ownership; business rules can be bypassed by direct writes. - Scaling and performance contention: one service's heavy queries affect others. - Harder to evolve towards independent services later. Mitigations that show maturity - Separate schemas per service, with each service owning its tables and database permissions restricting access to other schemas. - Rules that services read other domains' data only through APIs, events or read-only views — no direct writes across boundaries. - Backward-compatible migrations (expand and contract) coordinated through a shared migration review. - An outbox and events introduced for cross-service communication, preparing for a future split. - A roadmap to move the most independent service to its own database first. Example answer "We had a shared Azure SQL database because the services were carved out of a monolith with heavy cross-domain reporting, and the business needed the first services live within a quarter. We knew it coupled our deployments, so each service got its own schema and database user, cross-domain reads went through views, and we used an outbox to publish events. Later we moved the notifications service to its own database, since it had the fewest dependencies."
Ravindra Wadile · · 0 likes