Timedora

Database Foundations and Design Tradeoffs

A practical foundation for understanding database models, data integrity, transaction guarantees, distributed tradeoffs, and workload-driven system selection.

Data Models, Schemas, and Access Patterns

What a data model helps you decide

A is an organized collection of data managed by a management system (DBMS). Its data model describes how information and relationships are organized. Choosing a model is partly about the shape of the data and partly about how an application needs to retrieve and change it.

  • Relational databases organize records in tables, with rows and columns. Keys identify records and express relationships; constraints can enforce rules. SQL can combine information from multiple tables. This model suits structured data when relationships and correctness rules matter.

  • Key-value databases associate each unique key with a value. They suit lookups where the application already knows the key, such as retrieving a session or shopping cart.

  • Document databases store records as documents, often with nested fields and arrays. Documents may have different shapes, which can suit evolving or hierarchical information. Embedding related information can simplify common reads, though duplicated fields may need coordinated updates.

  • Graph databases represent entities as nodes and relationships as edges. They are useful when queries need to traverse relationships, such as finding connections in a social network.

  • Wide-column, time-series, and in-memory databases are other nonrelational models suited to particular storage or access patterns. “” or “nonrelational” names a broad family, not one uniform design or guarantee.

An online store illustrates how these models can complement one another: relational tables might hold orders, payments, and inventory, where constraints and multi-step updates matter; a document might suit a varied product catalog; and a key-value store might retrieve a cart by customer ID. These are possible fits, not rules. The actual and required guarantees determine the choice.

Schemas: structure and integrity

A defines the structure of stored data and may specify allowed types, required fields, uniqueness, and relationships. In a relational , table columns and constraints commonly define the . A document may allow documents with different fields, but flexible shapes do not mean data has no structure: applications can validate fields, and a deliberate helps keep records usable and consistent.

design should reflect both what the data means and how applications access it. Relational designs often reduce unnecessary duplication and use joins to combine related records. Document designs may embed information commonly read together, reducing separate lookups. That convenience can duplicate data, so the design must specify how copies stay correct when the underlying information changes.

Transactions and Correctness

A is one logical unit

A groups operations so they are treated as a logical unit. The properties describe important guarantees for such work:

  • Atomicity: the happens entirely or not at all.

  • Consistency: a successful preserves the ’s defined rules and constraints.

  • Isolation: concurrent transactions do not interfere in ways the chosen isolation level forbids.

  • Durability: committed changes survive failures covered by the system’s durability guarantees.

Consider transferring money between two accounts. The intended operation has two parts: subtract from one account and add to the other. If only the subtraction succeeds, the stored records no longer match the intended transfer. Treating both changes as one means they succeed together, or, if the cannot complete, the operation can be rolled back. This illustrates atomicity; consistency concerns preserving the ’s rules, while durability concerns committed results surviving covered failures.

Isolation and two meanings of consistency

Isolation levels offer different protections for concurrent work. Stronger isolation can prevent more anomalies, but may add overhead or cause a to fail and need a retry. The appropriate protection therefore depends on the application’s needs; “isolated” does not mean every system uses the same level of protection.

The word consistency also appears in discussions of distributed systems. There, it can describe whether a read immediately reflects a recent write. That meaning is related to, but distinct from, consistency, which is about preserving the ’s defined rules and constraints.

Availability, Scaling, and Network Partitions

Availability and growth

Availability describes whether a system can respond to requests when needed. —keeping copies of data on multiple machines—can help a service continue through some failures and can distribute read traffic. Replicas must be sufficiently up to date for the application, however: a read from a lagging replica may return older data.

Scalability is the ability to handle growth in data, requests, or users. Vertical scaling adds resources to a machine; horizontal scaling distributes work across machines. Partitioning, or , splits data among machines and can increase capacity, while making data placement and queries more complex. Keep the distinction clear: creates copies; divides the dataset. They address different problems.

What CAP says during a partition

A network partition prevents some nodes in a distributed system from communicating. During that partition, the system cannot guarantee both that every request receives a successful response and that every response reflects one globally consistent, up-to-date view. It may reject or delay some requests to preserve the stronger consistency guarantee, or it may continue responding while allowing temporarily divergent or stale results.

The condition matters: CAP’s tradeoff becomes unavoidable when a partition occurs. It does not mean a system simply chooses two properties under all conditions. and alone also do not determine which behavior a system provides; capabilities vary by system and configuration.

Choosing a for the

Match capabilities to requirements

No is best for every . Compare candidates using concrete requirements rather than assuming a relational or label guarantees particular behavior.

  1. Data and relationships: Is the information tabular, hierarchical, graph-shaped, or mainly retrieved by key? Are relationships and constraints central?

  2. Queries and access patterns: Which reads and writes must perform well? Are flexible queries and joins important, or are the main lookups known in advance?

  3. Correctness: Which operations must be atomic? Can the application tolerate stale reads or temporarily conflicting updates?

  4. Scale and latency: Estimate current and future data volume, request rate, response-time targets, and geographic distribution. Test realistic workloads instead of assuming a model will scale automatically.

  5. Operations and cost: Consider backups, recovery, monitoring, security, migration, staffing, service limits, and costs during both normal operation and growth.

A relational is often a sound starting point when structured data, flexible queries, constraints, and multi-record transactions matter. A nonrelational may fit better when its particular model matches the access pattern or scaling needs. These are starting points, not rules: capabilities for transactions, , consistency, availability, and scaling vary by product and configuration.

Some applications use multiple stores, assigning different parts of the to suitable systems. This can improve fit, but adds integration and operational complexity. The decision is therefore not just which model looks appropriate; it is whether the specific system, in its intended configuration, meets the application’s correctness, performance, scale, and operating needs.

  • : A limit on simultaneously guaranteeing successful responses to every request and one globally consistent, up-to-date view during a network partition.

  • : The practical work and resources needed to run, maintain, and support a system.