Quick revision
The short answer
Shared tables written directly with upserts are simple at first, but they couple many services to one schema, blur ownership and make every change a negotiation. An owning service that publishes reference data as events or through an API gives one writer, clear contracts and versioning, at the cost of eventual consistency and extra infrastructure; consumers keep local copies with idempotent, version-aware upserts and can rebuild from a compacted topic or a snapshot. I would decide by the number of writers, how often the data changes, how fresh consumers need it and where organisational boundaries lie, with one writer per dataset as the default, and migrate away from shared tables gradually using CDC.
What to remember
In this answer, we compared shared reference tables written with upserts, which are simple and immediately consistent but couple services to one unversioned schema with unclear ownership, with an owning service that publishes events or an API, which gives one writer and versioned contracts at the cost of eventual consistency and infrastructure. Consumers keep local copies with idempotent, version-aware upserts and rebuild from a compacted topic or snapshot, the decision rests on writers, change frequency, freshness and team boundaries, and CDC makes a gradual migration possible.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Shared tables written directly with upserts are simple at first, but they couple many services to one schema, blur ownership and make every change a negotiation. An owning service that publishes reference data as events or through an API gives one writer, clear contracts and versioning, at the cost of eventual consistency and extra infrastructure; consumers keep local copies with idempotent, version-aware upserts and can rebuild from a compacted topic or a snapshot. I would decide by the number of writers, how often the data changes, how fresh consumers need it and where organisational boundaries lie, with one writer per dataset as the default, and migrate away from shared tables gradually using CDC.
Why this question is asked
How reference data, such as products, prices, stores or currencies, is shared between services is one of those architectural choices that shapes a company for a decade. Early on, the shared database is the obvious answer: everyone already has access, and an upsert is one line. Years later, the same choice can mean that nobody can rename a column without a meeting of eight teams. At the most senior level, interviewers want to see that we can weigh both options honestly, choose with clear criteria, and plan a migration that does not stop the business. In this answer, we will look at what the shared-table model gives and costs, what the owning-service model gives and costs, how consumers keep local copies safely, how to decide, and how to move from one to the other with CDC.
1The Shared-Table Model and Where It Hurts
In the shared-table model, a reference table such as products lives in a database that several services can write to and read from. When the ERP sends a new price, whichever service receives it upserts the row. It is simple, consistent at once, since every reader sees the latest committed value, and needs no extra infrastructure. For a small company with three services and one team, this is a perfectly reasonable choice.
The costs appear as the company grows. The schema becomes a public interface of every service that touches it, so changing a column type requires coordinating every reader and writer, and nobody can be sure who depends on what. Several writers mean nobody owns the data: if two services upsert the same product from different sources, which one is right? Load from one service's heavy query affects all the others, and a bad migration by one team breaks everyone. In short, the database becomes the integration point, and it has no way to version a contract.
2The Owning-Service Model
In the owning-service model, exactly one service owns the products dataset. It is the only writer, it validates changes, and it publishes the data, either as events on a topic, such as ProductChanged with a version, or through an API that others can call. Consumers do not touch its tables. Instead, each consumer that needs product data keeps its own local copy, in the shape it needs.
This gives clear ownership, a single place where rules are enforced, and contracts that can be versioned: a schema registry for events, or versioned API endpoints, lets the owner evolve its internal tables freely and change the public contract only through a deliberate, compatible step. The cost is eventual consistency, since a consumer's copy lags the owner by milliseconds to seconds, and more infrastructure: a message broker, schemas, consumers to run and monitor, and the operational skills to do so.
| Concern | Shared tables + upserts | Owning service + events |
|---|---|---|
| Writers | many, unclear ownership | exactly one |
| Contract | the table schema, unversioned | event schema or API, versioned |
| Consistency | immediate | eventual, usually seconds |
| Changing the model | coordinate every team | owner changes internals freely |
| Infrastructure | just the database | broker, schemas, consumers |
| Failure isolation | one bad query hurts all | consumers isolated by local copies |
3How Consumers Keep Local Copies
A consumer's local copy must stay correct even though events can be delivered twice or out of order. So the consumer applies each event with an idempotent, version-aware upsert: insert or update only if the incoming version is newer than the stored one. Deletions arrive as tombstone events and are applied the same way.
6 messages in order. Play them, or step through them one at a time.
The consumer also needs a way to start from scratch, for a new service or after a bug corrupts its copy. A Kafka topic with log compaction keeps at least the latest event for every key, so a consumer can read the whole topic from the beginning and end up with the full current dataset. Alternatively, the owner offers a snapshot export or a paged API, and the consumer loads the snapshot and then continues from the events after it.
4How I Would Decide
I would not apply one answer to every dataset. The questions I ask are these. How many services need to write it? If more than one, shared tables leave ownership unclear, and that alone pushes toward a single owner. How often does it change, and how fresh must consumers be? A currency list that changes twice a year can be shared or even copied as a file; product prices changing every minute benefit from events. Does any consumer need strict read-your-writes consistency with the owner? Then it should call the owner's API for that case. And where are the organisational boundaries? Data shared within one team's services can stay in one database; data crossing team boundaries should cross through a contract.
My default is one writer per dataset, with the owning team publishing events for data that changes often and offering an API for lookups. Shared tables are acceptable inside one team's boundary or for small, rarely changing lists, as long as there is still only one writer.
5Migrating From Shared Tables With CDC
Most companies asking this question already have shared tables, and a big-bang rewrite is too risky. Change data capture gives a gradual path. A tool such as Debezium reads the database's change log and publishes every change to the shared table as an event. Consumers can switch from reading the table to consuming the events one at a time, while the table still works for everyone else.
Then we move the writes. One service is declared the owner, and the other writers are changed to send their updates to it, through its API or commands, instead of writing the table. Once the owner is the only writer, it can switch from raw CDC events, which expose its table structure, to well-designed domain events published through an outbox table, and the old shared table becomes private to the owner. Each step is small, reversible and can be done team by team.
6Follow-up questions
Isn't eventual consistency a problem for prices at checkout?
It can be, so we design for it. The checkout service can use its local copy to display prices and then confirm the final price with the owner's API, or include the price version in the order so a stale price is detected and the customer is asked to confirm. Most reference data tolerates a few seconds of lag without anyone noticing.
Why use an outbox instead of publishing events directly from the service?
Writing to the database and publishing to Kafka are two separate systems, so a crash between them can lose an event or publish one for a change that rolled back. With an outbox, the service writes the event into a table in the same transaction as the data change, and a relay or CDC publishes it afterwards, so data and events never diverge.
7Conclusion
In this answer, we compared shared reference tables written with upserts, which are simple and immediately consistent but couple services to one unversioned schema with unclear ownership, with an owning service that publishes events or an API, which gives one writer and versioned contracts at the cost of eventual consistency and infrastructure. Consumers keep local copies with idempotent, version-aware upserts and rebuild from a compacted topic or snapshot, the decision rests on writers, change frequency, freshness and team boundaries, and CDC makes a gradual migration possible.
Open with
Shared tables with direct upserts are genuinely simple at the start: no infrastructure, and every reader sees the latest value immediately. The long-term cost is coupling. The table schema becomes an unversioned contract for every service that touches it, several writers mean no clear owner, and changing a column needs every team in the room.
Then, if they want more
An owning service that publishes reference data as events or through an API gives one writer, validation in one place, and versioned contracts, so the owner can change its internals freely. The price is eventual consistency and more infrastructure: a broker, schemas, consumers.
Consumers keep local copies with idempotent, version-aware upserts, applying an event only if its version is newer, and they can rebuild from a compacted Kafka topic or a snapshot.
I'd decide per dataset by the number of writers, how often it changes, how fresh consumers need it, and whether it crosses team boundaries; my default is one writer per dataset, with events for frequently changing data. Small, rarely changing lists inside one team can stay shared.
For migration, I'd use CDC with Debezium to publish changes from the existing table so consumers move gradually, then route all writes through the owner, and finally switch to domain events through an outbox.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, The SQL Language
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your company is choosing between letting services write directly to shared reference...": https://scrivio-interview-library.netlify.app/databases/sql-fundamentals/16034366cc/