API / Microservices Design Patterns Interview Questions
What is the Shared Database anti-pattern and why should it be avoided in microservices?
The Shared Database anti-pattern occurs when two or more microservices bypass each other's APIs to directly read from and write to the same database schema. It is the most common mistake teams make when splitting a monolith, because it initially appears to be the easiest path — split the code but keep a single database.
Why it fundamentally undermines the microservices model:
- Schema coupling — any team wanting to rename a column, add a NOT NULL constraint, or change a table structure must coordinate with every team whose service touches that table. A simple schema change becomes a multi-team, multi-sprint event.
- Loss of independent deployability — if Service A changes the
orderstable, Service B and Service C must be updated and redeployed simultaneously. The services cannot be independently deployed. - Hidden dependencies — the coupling is invisible at the API level. No OpenAPI spec, no contract test, captures it. It surfaces unexpectedly as a runtime breakage during incidents.
- Technology lock-in — all services are forced to use the same database engine, preventing polyglot persistence and specialised data modelling.
- Operational coupling — a runaway query or bulk migration in one service can saturate the shared database's connection pool and I/O capacity, degrading every other service that shares the same instance.
The correct alternative is the Database per Service pattern (Q8), with cross-service reads handled via API Composition (Q14) or CQRS (Q12), and cross-service writes handled via Sagas (Q10). The short-term pain of separating data stores pays back quickly in deployment independence and incident isolation.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
