Suppose you've extracted customer service from a monolith, but the monolith still reads and updates the customer tables. The two applications deploy separately. A column rename can still break either one, and both can change the same address through different validation rules. Moving the tables to another database server would also break any transaction that updates customer and order data together.
I'll focus on the period when the monolith and the new service both need the same data. These five patterns help you choose how to preserve access while you move ownership. The names follow Sam Newman's Monolith to Microservices pattern catalog. You can combine them during a migration; the numbering doesn't prescribe an implementation sequence.
Database decomposition patterns for an incremental migration
1. Change data ownership
Give the Customer service responsibility for customer updates and the rules those updates must follow. When the monolith changes a delivery address, it calls the Customer service instead of updating the customer table directly.
I'd assign one owner to each set of business data before moving it to another database. Here, ownership means authority over writes and business rules. A Customer service may own several tables, including addresses and contact preferences. Use the domain boundary to group them; the guide to DDD bounded contexts explains how to find that boundary.
You can establish ownership while the tables stay on the existing database server. For microservices, Microsoft explicitly allows shared physical database infrastructure while keeping each store private. Give the service its own credentials, migrate the other write paths, then remove their direct write permissions. Include imports and scheduled jobs in that inventory. One forgotten job can bypass the new rules.
Cost. A monolith transaction that changes both an order and a customer now crosses an API boundary. Decide how that operation will maintain its business rules before handing over writes. Any direct readers you retain still depend on the schema, and sharing the server still means sharing capacity and failures.
2. Add a database wrapping service
Put a separate service in front of the legacy database and move callers to its API. The wrapper translates requests into queries, so callers can stop depending on table and column names.
I'd use a database wrapper when several callers need a stable API while the schema changes. For example, a caller asks for a customer:
GET /customers/42
200 OK
{"id": 42, "displayName": "Ada"}The wrapper can build displayName from given_name and family_name, then keep the same response after the storage model changes. Migrate callers to that contract on their own release schedules. Define the fields and operations callers need. An endpoint that accepts arbitrary SQL would leave those callers tied to the schema.
A wrapper can centralize access before you move the business rules. During that stage, validation may still live in the monolith. Record which component owns those rules, and narrow the wrapper as domain services take over its responsibilities.
Cost. You operate another deployment and add a network call to each migrated access path. If one wrapper serves unrelated domains, its releases can become a shared dependency. Remove the temporary routes once their callers use the owning services directly.
3. Synchronize data in the application
Keep a second copy of the data while you move readers to a new store. The application that owns the writes also records the changes the second store needs. This helps when you must change the storage model while the old application continues working.

I'd keep one authoritative writer while the second store catches up. Suppose the monolith saves a customer's new address, then writes that address to the new database. If the second database is unavailable, the first write has already committed. Retrying only the HTTP request doesn't tell you which changes still need copying.
One implementation uses a transactional outbox. Save the address and an outbox record in the same local transaction. A relay later sends the change to a consumer that updates the second store.
The AWS outbox guidance describes this failure window and the need to handle duplicate messages. The target should apply a repeated message safely and use an ordering or version rule so an older address can't overwrite a newer one. The Inbox and Outbox guide covers the local transaction and deduplication mechanics.
Copy the existing records in a backfill. Coordinate that copy with incoming updates and deletions, compare the stores, then switch reads when the copy is ready. A row count alone won't reveal an incorrect address. If write ownership also moves, explicitly switch the authoritative writer and stop the old write path.
Cost. Propagation takes time, and an outbox doesn't make both databases commit atomically. Monitor lag and failed updates, and provide a way to replay or repair missing changes. A read that must immediately reflect a completed write needs an authoritative read path until the copy catches up.
4. Use a database view
A view lets an existing SQL reader keep a stable set of columns while you change the underlying tables. It fits consumers that need to keep querying the database during the migration.
I'd use a view when an existing SQL reader needs a stable set of columns. For example, expose the customer's public name through a PostgreSQL view:
CREATE VIEW customer_public AS
SELECT id, given_name || ' ' || family_name AS display_name
FROM customer;A query against customer_public returns id and display_name. Later, you can change the view's query while preserving those output names and types. Use explicit columns and keep the old contract until its consumers migrate, as in the expand, switch, and contract approach.
Give this consumer read-only access to the view and remove its direct access to the base tables. Views aren't inherently read-only: PostgreSQL supports updates through some simple views, so configure permissions for the contract you intend to expose.
Limit. An ordinary PostgreSQL view runs its query against the underlying tables. It doesn't create an independently available copy. The consumer still shares the database's load and availability, and a later move to a separate database needs another access mechanism.
5. Use the monolith as a data access layer
Expose a narrow API inside the monolith when an extracted service still needs data and rules that belong there. A new Shipping service can request a customer's delivery address through the monolith instead of reading the legacy customer tables.
I'd keep the data behind the monolith's API while its business rules still live there. For example, the monolith may already select the current delivery address and check whether the caller can access it. Shipping can use that result without reproducing the queries and authorization checks.
The API runs inside the existing monolith. The database wrapper in pattern 2 runs as a separate service. Keeping the endpoint in the monolith lets it reuse the existing implementation, while giving Shipping a contract that can survive a later extraction. Return the fields Shipping needs, and keep legacy table structures out of the response.
Limit. Shipping now depends on the monolith's response time and availability for that request. When the customer capability moves, preserve the API contract and redirect its callers to the new owner. If customer data remains the monolith's responsibility, keeping that API can remain a valid design.
Comments (0)