Part 4 of 5 · 3 min read
The cost of polyglot persistence
Running several different data stores well fits each part's access pattern, but adds real operational and consistency cost across the whole system.
The cost of polyglot persistence
Think of that same restaurant again. Three different storage areas each suit what they hold, but the kitchen now needs three different sets of staff trained to use them, and a mistake moving an ingredient between them is easy to make.
In plain words: polyglot persistence fits each piece of data to its best model, but it is not free. Each additional data store is another system to operate, monitor, back up and keep available. Keeping data consistent across stores, such as a customer's name appearing in both the relational catalog system and a cached key-value profile, now requires deliberate synchronization, since no single database enforces it automatically across store boundaries. A smaller system, or a team without the operational capacity to run several kinds of store well, may reasonably choose one single model everywhere, accepting a worse fit for some of its data in exchange for far less operational complexity.
A worked example. If the bookstore's customer name changes in the relational system but the key-value cart cache still holds the old name, nothing in either store catches this mismatch automatically; the bookstore's own application code has to keep the two in sync, for instance by updating or expiring the cached copy whenever the underlying record changes.
The key lines. No new SQL; this part is an operational trade-off, not a query.
Cross-store consistency
Cross-store consistency is the problem of keeping the same fact correct across more than one data store, when no single database can enforce it automatically. It has to be maintained deliberately, typically by application code updating or invalidating a cached or duplicated copy whenever the original changes.
Example: a customer's name changing in the relational catalog without the key-value cart cache being updated to match is a cross-store consistency problem polyglot persistence introduces.
Remember this
The right data model for any piece of data follows from its own access pattern, not from habit. A real system commonly ends up using more than one model at once, called polyglot persistence, trading a better fit per piece of data for the added operational and consistency cost of running several kinds of store together. Level 12 turns to a different question: what changes once the workload shifts from ordinary transactions to analytics over the whole dataset.
Quick notes
- The right data model follows from a specific piece of data's own access pattern: how it is read, written, and looked up.
- Relational fits stable relationships queried in varied ways; document fits self-contained, mostly-whole records; key-value fits exact-key lookups; graph fits highly connected data; column-family fits high-volume, mostly-append data read back by key and time range.
- Polyglot persistence is using more than one data store within one system, each fitted to the part of the system it actually serves.
- Polyglot persistence adds real operational cost, more systems to run, and a cross-store consistency problem no single database can solve automatically.
- A smaller system may reasonably choose one model everywhere, trading a worse fit for less operational complexity.