Database Management Systems

Chapter 12
NoSQL and Polyglot Persistence

Bachelors Program in AI & ML
Database Management Systems   •   Bachelor

NoSQL and Polyglot Persistence

Introduction

Relational database management systems remain central to information systems because they provide strong transactional guarantees, a mature query language, and a powerful data model based on relations. However, modern applications also process social connections, sensor streams, product catalogs, user activity, cached sessions, and rapidly changing semi-structured data. These workloads may require horizontal scalability, flexible schemas, very low latency, or specialized query capabilities that are not always efficiently provided by a single relational database.

NoSQL is a broad family of non-relational database technologies. The term does not mean “no SQL” in every case; many NoSQL systems provide SQL-like languages or SQL interfaces. More usefully, NoSQL systems commonly emphasize one or more of the following: flexible data models, distributed operation, horizontal scaling, workload-specific optimization, and tunable consistency.

Polyglot persistence is the deliberate use of multiple data technologies within one application or organization. A system might use a relational database for financial transactions, a document database for product information, a graph database for recommendations, and an in-memory store for sessions. The objective is not to replace relational databases, but to select storage technologies according to workload requirements.

Learning Objectives

After completing this chapter, a student should be able to:

1. Explain the motivations, characteristics, and trade-offs of NoSQL databases.

2. Compare key–value, document, wide-column, graph, time-series, and in-memory databases.

3. Model and query non-relational data using representative data structures.

4. Evaluate denormalization, replication, partitioning, and eventual consistency.

5. Select a database technology using workload, consistency, latency, scalability, and governance criteria.

6. Describe the architectural and operational consequences of polyglot persistence.

1. Why Non-Relational Databases Emerged

Traditional relational design represents data in tables with predefined schemas. Normalization reduces duplication and protects integrity, while joins support flexible combinations of data. This model is highly effective for many business systems. Nevertheless, several contemporary pressures have encouraged alternative designs:

  • Data variety: JSON documents, graph relationships, logs, multimedia metadata, and sensor measurements do not always fit naturally into fixed tables.
  • Large scale: Internet applications may require distribution across many commodity servers.
  • High request rates: Applications such as advertising, gaming, and social media may need predictable low-latency reads and writes.
  • Rapid schema evolution: Agile applications may add attributes frequently or store different attributes for different entities.
  • Specialized access patterns: A graph traversal, a time-window aggregation, or a direct lookup may be better served by a specialized engine than by general-purpose joins.

NoSQL design does not eliminate modeling. It changes the starting point: instead of first creating a normalized representation and then writing queries, designers often begin with the application’s access patterns and organize data for those operations.

2. Fundamental Concepts and Trade-offs

2.1 Schema flexibility

A relational database usually defines columns and types before inserting data. A document database may allow two documents in the same collection to contain different fields. Schema flexibility supports evolution but can produce inconsistent data. Flexibility therefore shifts some responsibility from database constraints to application code, validation services, or governance processes.

“Schema-less” is an imprecise expression. Every stored value has structure, even if the database does not enforce one global schema. A robust system normally documents fields, validates important attributes, and manages schema versions.

2.2 Horizontal scaling and partitioning

Vertical scaling increases the capacity of one machine. Horizontal scaling distributes data and requests across multiple machines. A partition key determines where a record is stored. A good key distributes load evenly and supports common queries. A poor key may create a hot partition, in which one server receives disproportionate traffic.

Partitioning improves capacity but complicates cross-partition queries, transactions, rebalancing, and operational monitoring. Partition-key selection is therefore a data-modeling decision, not merely an infrastructure setting.

2.3 Replication and availability

Replication stores copies of data on multiple nodes. It can improve availability and read throughput, but introduces coordination and failure-management issues. Replicas may temporarily disagree after a write. Systems differ in whether they offer leader-based replication, multi-leader replication, quorum protocols, or conflict resolution.

The CAP theorem is often summarized as a choice between consistency and availability during a network partition. More precisely, when a partition prevents nodes from communicating, a distributed system cannot simultaneously guarantee both linearizable consistency for every operation and availability for every request. CAP does not say that a system must permanently choose only two properties, nor does it replace detailed analysis of latency, durability, and transaction semantics.

2.4 Consistency models

  • Strong or linearizable consistency: a read reflects the latest completed write according to a single real-time order.
  • Eventual consistency: if updates stop and communication continues, replicas eventually converge; a read may temporarily return an older value.
  • Causal consistency: causally related operations are observed in an order that preserves their cause-and-effect relationship.
  • Session guarantees: properties such as read-your-writes can provide useful user-level behavior without global linearizability.

Eventual consistency is not automatically incorrect. It is suitable for data such as social counters, recommendations, and replicated catalogs when temporary staleness is acceptable. It is unsuitable for operations where stale data can cause unacceptable harm, such as preventing a bank account from becoming overdrawn without additional safeguards.

2.5 Denormalization

Denormalization deliberately duplicates data to reduce joins and improve read performance. For example, an order document may embed delivery-address fields so that an order screen can be rendered with one read. The cost is update complexity: when an address changes, copies may become inconsistent.

Denormalization should be guided by access patterns. Frequently read, relatively stable data is often a good candidate for duplication. Highly volatile data or data requiring a single authoritative value should usually remain centralized or be updated through a carefully designed workflow.

3. Major NoSQL Data Models

3.1 Key–value databases

A key–value database stores a unique key and an opaque value. The value may be a string, binary object, JSON value, or serialized application object. Typical operations are put, get, update, and delete.

Example:

```text

Key: session:8f31

Value: {userId: 204, role: "student", expiresAt: "2026-06-01T10:00:00Z"}

```

Key–value stores are effective for sessions, shopping carts, feature flags, idempotency records, counters, and caching. They generally perform poorly when users need arbitrary queries over fields inside values, complex joins, or multi-record analytical operations. Some systems add secondary indexes, but extensive querying may indicate that another model is more suitable.

3.2 Document databases

A document database stores self-contained documents, commonly represented as JSON or BSON. Documents can contain nested objects and arrays.

```json

{

"orderId": "O1007",

"customerId": "C42",

"items": [

{"productId": "P9", "quantity": 2, "unitPrice": 19.50}

],

"status": "paid",

"shipping": {"city": "Leeds", "country": "UK"}

}

```

Documents are useful when an aggregate is normally read and written together. Embedding order items avoids a join during order retrieval. Referencing is preferable when a related entity is large, shared by many documents, or updated independently.

Document query systems commonly support predicates, projections, indexes, array operations, and aggregation pipelines. Indexes improve reads but consume storage and make writes more expensive. A design should index actual query patterns rather than every possible field.

3.3 Wide-column databases

Wide-column databases organize data by a row key and a set of columns, often distributed across a cluster. Rows need not have identical columns. The model is particularly effective for very large, write-intensive datasets queried by known keys and ranges.

A table for device readings might use:

```text

Partition key: device_id

Clustering key: reading_time

Columns: temperature, humidity, battery_level

```

If queries frequently retrieve one device over a time range, this layout is appropriate. If queries instead group all devices by an arbitrary attribute, the table may require another design or a separate analytical system. In many wide-column systems, tables are designed around queries and duplication across tables is normal.

The distinction between a wide-column database and a relational table is important: the physical distribution model, partition behavior, and query restrictions are central to design. A syntactically table-like interface does not imply relational capabilities such as unrestricted joins.

3.4 Graph databases

A graph database represents entities as nodes and relationships as edges. Both may have properties. For example:

```text

(Ada)-[:FOLLOWS]->(Ravi)

(Ada)-[:PURCHASED {date: "2026-02-03"}]->(Book17)

```

Graph databases are suitable for fraud detection, recommendation, network analysis, identity relationships, and knowledge graphs. Their strength is traversing relationships whose paths are difficult to predict in advance. A graph query may ask for friends-of-friends who purchased a particular category, subject to path and filtering constraints.

Graphs are not automatically superior for every connected dataset. If the dominant operation is a simple lookup by customer identifier, a key–value or relational design may be cheaper and simpler. Graph performance depends on traversal depth, branching factor, indexes, memory, and data distribution.

3.5 Time-series databases

Time-series databases optimize measurements indexed by time, often together with a device, location, or metric name. Typical operations include append, range retrieval, downsampling, retention, and window aggregation.

A time-series record might contain timestamp, sensor identifier, temperature, and quality status. Good designs distinguish tags used for filtering from fields containing measurements. Excessive tag cardinality—for example, generating a unique tag for every event—can harm indexing and storage efficiency.

Time-series systems commonly support retention policies and rollups. Raw measurements may be retained for thirty days, while hourly averages are retained for several years. Aggregation must account for missing values, outliers, sampling intervals, and the semantics of averages; an average of averages is not generally valid unless weighted by the number of observations or otherwise justified.

3.6 In-memory databases

An in-memory database keeps active data primarily in RAM, reducing storage latency. It may provide persistence through snapshots, logs, or replication, but durability characteristics vary. In-memory systems are used for caching, sessions, leaderboards, rate limiting, queues, and fast counters.

A cache is not automatically the system of record. If cached data is lost, the authoritative database must still support reconstruction. Designers should define expiration, invalidation, maximum memory behavior, and failure recovery. Cache-aside is common: the application reads the primary store on a cache miss and then populates the cache. This pattern is simple but can produce stale values and cache stampedes unless carefully controlled.

4. Modeling and Querying Non-Relational Data

4.1 Access-pattern-first modeling

A practical workflow is:

1. List business operations, such as “retrieve a user’s recent orders” or “find devices with abnormal readings.”

2. Estimate read and write frequency, response-time targets, data volume, and retention.

3. Identify the aggregate or partition boundary for each operation.

4. Select keys that distribute load and support the dominant queries.

5. Decide which data to embed, reference, duplicate, index, or precompute.

6. Define consistency and recovery requirements.

7. Test with representative data volume and concurrency.

This process is not permission to ignore conceptual modeling. Entities, ownership, constraints, and lifecycle still matter. Rather, the physical model is derived from observed use rather than from normalization alone.

4.2 Example: catalog and order data

A product catalog may use documents because products differ by category: a laptop has memory and processor attributes, while clothing has size and fabric attributes. An order may embed immutable product name and price at purchase time, while referencing the current product record for later catalog information. This preserves historical accuracy without requiring every order display to join live catalog data.

A key–value store may hold `cart:C42`, an in-memory representation of an active shopping cart. A relational database may remain the authoritative store for payment and settlement. A search engine may maintain a denormalized index for text search. This is already a polyglot architecture, even if users experience it as one application.

4.3 Query limitations and application joins

Some NoSQL systems intentionally restrict joins. When related data is needed, the application may issue multiple reads, embed the data, or maintain a materialized view. Application-side joins can increase latency and create consistency challenges. They should be measured rather than assumed to be inexpensive.

Materialized views are precomputed representations optimized for particular queries. They reduce read work but require refresh logic, failure handling, and monitoring of staleness. Event-driven updates can maintain such views asynchronously, introducing eventual consistency.

5. Polyglot Persistence Architecture

Polyglot persistence assigns different responsibilities to different stores. A sensible architecture might contain:

  • a relational core for users, payments, and inventory transactions;
  • a document store for flexible product content;
  • a graph store for recommendations and identity relationships;
  • a time-series store for operational telemetry;
  • an in-memory store for sessions and hot data;
  • an analytical warehouse or lake for historical reporting.

The central design principle is source-of-truth clarity. For each important fact, the team should document which store owns it, which stores contain projections, how updates propagate, and how conflicts are resolved.

Data synchronization may use change data capture, an event log, messaging, scheduled pipelines, or application-level dual writes. Dual writes—writing independently to two systems in one request—are vulnerable to partial failure. A transactional outbox pattern reduces this risk: the application writes the business change and an outbound event to the same transactional store; a reliable publisher later delivers the event to other systems.

Polyglot persistence increases operational complexity. Teams must manage different backup mechanisms, security models, drivers, monitoring tools, consistency semantics, and staff skills. The performance benefit must therefore justify the total cost of ownership.

6. Selecting a Database: A Workload-Based Framework

Database selection should begin with requirements, not product popularity. Important dimensions include:

| Dimension | Questions |

|---|---|

| Data shape | Is the data tabular, nested, connected, temporal, or opaque? |

| Access pattern | Are operations key lookups, range queries, traversals, search, or aggregation? |

| Consistency | Can stale reads be tolerated? Are multi-record transactions required? |

| Scale | What are current and projected data volume, throughput, and growth rate? |

| Latency | What are average and tail-latency targets? |

| Availability | What failures must the system tolerate? |

| Operations | Can the organization operate the technology reliably? |

| Governance | Are auditability, locality, encryption, and retention required? |

A useful decision is not “Which database is best?” but “Which database is best for this workload and constraint set?” Benchmarks should use realistic data distributions, query mixes, failure conditions, and concurrency. Average latency alone is inadequate; the 95th or 99th percentile may determine user experience.

7. Detailed Illustrative Case: MetroFleet Monitoring

Background

MetroFleet operates 40,000 delivery vehicles. Each vehicle emits location, engine, and temperature measurements. Drivers use a mobile application to receive routes, while customers view delivery progress. The company also wants to detect suspicious route behavior and forecast maintenance needs.

Problem

A single relational database has become difficult to scale. Telemetry inserts compete with customer queries, route relationships are difficult to analyze, and mobile sessions require very fast access. Management proposes replacing the relational database with one NoSQL product.

Analysis

The workloads are not identical. Telemetry is append-heavy and time-indexed. Driver sessions are short-lived key–value data. Route and vehicle relationships require graph traversals. Payments and contractual records require strong transactional integrity and auditability. A single database would force compromises and would not necessarily reduce complexity.

Approach and solution

The architecture uses:

  • a time-series database for high-volume measurements, with vehicle and measurement time as the principal access dimensions;
  • an in-memory key–value store for driver sessions and current route state, with expiration and reconstruction from authoritative services;
  • a graph database for vehicle–driver–route–depot relationships and suspicious connection analysis;
  • a relational database for billing, contracts, and maintenance work orders;
  • an event stream to distribute approved changes and build derived views;
  • an analytical platform for long-term forecasting and reporting.

The system declares the relational database authoritative for financial and contractual facts. The current route shown to customers is a materialized projection and may be a few seconds stale. Safety-critical alerts bypass eventually consistent displays and use a controlled alerting workflow with explicit acknowledgements.

Outcome

The design isolates workloads, permits independent scaling, and makes consistency decisions explicit. It also introduces costs: multiple backup policies, event replay procedures, schema contracts, and specialized operational skills. The organization therefore establishes service ownership, data lineage documentation, monitoring for projection lag, and disaster-recovery exercises.

Learning points

1. Polyglot persistence is justified by distinct workload characteristics, not by fashion.

2. A projection must not be confused with its source of truth.

3. Consistency requirements vary by business operation.

4. Operational complexity is part of database selection.

8. Challenges, Governance, and Contemporary Practice

NoSQL systems can create data-quality problems when validation is weak. Organizations should define ownership, field standards, versioning, retention, and access controls. Personally identifiable information must be minimized, encrypted in transit and at rest, and deleted or anonymized according to applicable law and organizational policy. Replicas, caches, logs, backups, and derived stores may all contain personal data and must be included in governance reviews.

Security design includes least-privilege identities, network segmentation, secret management, audit logging, patching, and tested backup restoration. Availability claims should be supported by recovery-time and recovery-point objectives, not merely by vendor descriptions.

Contemporary systems increasingly combine operational databases with event streaming, search, vector retrieval, and analytical platforms. AI applications may use vector indexes to retrieve semantically similar content, but a vector store is not a general substitute for transactional or relational storage. Metadata, access permissions, source citations, and deletion workflows must accompany embeddings. AI-generated results also require evaluation for relevance, privacy leakage, and stale knowledge.

Best practices include:

  • model from real access patterns and business invariants;
  • define the source of truth for every critical fact;
  • use schema validation and versioned contracts even with flexible stores;
  • select partition keys using expected scale and skew;
  • measure tail latency, not only averages;
  • test failure, replica lag, recovery, and reprocessing;
  • make denormalized update paths observable and idempotent;
  • avoid distributed transactions unless their value justifies their cost;
  • document retention, deletion, lineage, and ownership;
  • prefer the simplest technology that satisfies requirements.

Chapter Summary

NoSQL databases provide alternative data models and distribution strategies for workloads involving flexible structure, large scale, specialized access patterns, or low latency. Key–value systems excel at direct lookup; document systems represent aggregate-oriented JSON data; wide-column systems support distributed, high-volume access by designed keys; graph databases optimize relationship traversal; time-series databases manage temporal measurements; and in-memory systems provide rapid access to hot or ephemeral data.

These technologies involve trade-offs. Flexible schemas can weaken uniform validation, denormalization improves reads but complicates updates, partitioning supports scale but restricts some queries, and eventual consistency improves availability or latency at the cost of temporary staleness. Polyglot persistence combines technologies so that each workload uses an appropriate store, but it requires clear source-of-truth definitions, reliable synchronization, governance, monitoring, and operational expertise.

Database selection should therefore be workload-driven. Data shape, access patterns, consistency, latency, scale, availability, security, regulatory obligations, and organizational capability must be evaluated together. The most effective architecture is not the one with the greatest number of databases, but the one whose complexity is justified by measurable requirements.

Key Terms

NoSQL: A family of non-relational database technologies emphasizing flexible models, distribution, or workload specialization.

Polyglot persistence: The use of multiple data-storage technologies in one application or organization.

Key–value database: A store that retrieves opaque values using unique keys.

Document database: A database storing self-contained, often JSON-like documents.

Wide-column database: A distributed store organized around row keys and flexible columns.

Graph database: A database representing nodes, edges, and their properties.

Time-series database: A database optimized for timestamped measurements and temporal queries.

In-memory database: A database keeping active data primarily in RAM for low latency.

Partition key: A value used to determine the distribution location of a record.

Hot partition: A partition receiving disproportionate traffic or data.

Replication: Maintaining multiple copies of data on different nodes.

Eventual consistency: A model in which replicas converge if updates stop and communication continues.

Denormalization: Deliberate duplication or restructuring of data to optimize access.

Materialized view: A precomputed representation maintained for efficient querying.

Source of truth: The authoritative system responsible for a fact.

Change data capture: The recording and propagation of changes from a data source.

Transactional outbox: A pattern storing a business change and its outbound event in one transaction.

Tail latency: High-percentile response time, such as the 95th or 99th percentile.

Schema validation: Rules ensuring that stored data conforms to required structure and constraints.

Review Questions

Short Answer Questions

1. What is polyglot persistence, and why might an organization adopt it?

2. State two advantages and two risks of denormalization.

3. What is a hot partition?

4. Distinguish eventual consistency from linearizable consistency.

5. Give one appropriate use case for a graph database.

Long Answer Questions

1. Compare key–value, document, and wide-column databases in terms of data model, query style, and suitable workloads.

2. Explain how access-pattern-first modeling changes the design process compared with normalization-first relational design.

3. Discuss the benefits and operational costs of polyglot persistence.

4. Explain why partition-key selection is important in distributed NoSQL systems.

5. Analyze the security, privacy, and governance issues introduced by replicated and denormalized data.

Analytical / Application Questions

1. Design a storage architecture for an online marketplace that needs product flexibility, payment integrity, fast sessions, text search, and sales analytics. Identify the source of truth and consistency model for each major component.

2. A sensor application queries one device’s readings for a time range but occasionally asks for all devices reporting abnormal values. Propose a wide-column or time-series design, identify its limitations, and suggest an additional analytical solution if necessary.

3. An application writes an order to a relational database and independently updates a document store. Analyze the failure scenarios and propose a more reliable synchronization pattern.

Multiple Choice Questions with Answers

Question 1

Which workload is most naturally suited to a key–value database?

A. Multi-hop relationship traversal

B. Direct retrieval of a user session by session identifier

C. Ad hoc joins across financial tables

D. Long-term statistical analysis of all sensor readings

Correct Answer: B. Direct retrieval of a user session by session identifier

Question 2

What is the main reason for embedding related data in a document?

A. To guarantee global serializability

B. To eliminate the need for all indexes

C. To retrieve an aggregate with fewer joins or round trips

D. To ensure that duplicated values always update automatically

Correct Answer: C. To retrieve an aggregate with fewer joins or round trips

Question 3

What is a hot partition?

A. A partition encrypted with a temporary key

B. A partition receiving disproportionately high traffic or data

C. A partition containing only historical records

D. A partition that has been removed from replication

Correct Answer: B. A partition receiving disproportionately high traffic or data

Question 4

Which database model is especially appropriate for relationship traversal?

A. Graph

B. Key–value

C. Time-series

D. In-memory cache only

Correct Answer: A. Graph

Question 5

What does eventual consistency guarantee, assuming updates stop and communication continues?

A. Every read immediately returns the newest value

B. All replicas eventually converge

C. Every operation is globally transactional

D. No replica can temporarily return stale data

Correct Answer: B. All replicas eventually converge

Question 6

Which practice best clarifies data ownership in a polyglot architecture?

A. Allow every store to update the same fact independently

B. Define a source of truth for each critical fact

C. Avoid documenting derived views

D. Use the same schema for every database

Correct Answer: B. Define a source of truth for each critical fact

Question 7

Which pattern stores a business change and its outbound event in the same transaction?

A. Cache-aside

B. Read-your-writes

C. Transactional outbox

D. Round-robin partitioning

Correct Answer: C. Transactional outbox

Question 8

Why can excessive secondary indexes be harmful?

A. They always prevent replication

B. They consume resources and can increase write cost

C. They remove all schema information

D. They guarantee stale reads

Correct Answer: B. They consume resources and can increase write cost

Question 9

Which workload best fits a time-series database?

A. Timestamped measurements queried by device and time range

B. Arbitrary multi-hop social relationships

C. Opaque session retrieval by token

D. Payment settlement requiring relational constraints

Correct Answer: A. Timestamped measurements queried by device and time range

Question 10

Why should database benchmarks examine tail latency?

A. Average latency is always mathematically invalid

B. High-percentile delays can determine user experience and service objectives

C. Tail latency measures only storage capacity

D. Tail latency eliminates the need for failure testing

Correct Answer: B. High-percentile delays can determine user experience and service objectives

Database Management Systems
Chapter 12 of 15