Database Selection in System Design
Choosing Databases for System Design
A database choice affects much more than where information is stored. It influences whether a system can meet its performance, reliability, and growth requirements. In system design, the same feature can often be built with several kinds of databases, but those databases may behave very differently as the system grows or its queries become more demanding.
A useful starting point is to separate functional requirements from non-functional requirements. Functional requirements describe what the system must do—for example, let a customer place an order. Non-functional requirements describe how well it must do it, such as how quickly it responds, how reliably it preserves data, and how much traffic it can handle. A database choice often has a greater effect on the non-functional requirements than on the basic feature itself.
Three questions guide the choice:
- What is the structure of the data? Is it highly organized into consistent fields, or does it vary widely?
- How will the data be queried? Will requests look up individual records, search text, or retrieve large time ranges?
- What scale must the system handle? How much data arrives, and how quickly is it growing?
The sections below connect common requirements to database categories and explain why particular choices fit.
A database should be chosen to match the data, the access patterns, and the scale—not simply because it is familiar.
Think About It: If two systems store similar information but query it in very different ways, why might they benefit from different databases?
Caching for Frequently Needed Results
A cache stores data that a system expects to need again soon, allowing it to avoid repeating an expensive operation. For example, a service may query a database for a result and keep that result in a cache. A later request for the same information can then be answered without querying the database again.
Caching can also help when a system calls a remote service. If that service is slow to respond, the calling system may store a response locally and reuse it when appropriate. In both cases, the cache reduces repeated work and can make responses faster.
Caches commonly use a key–value structure. The key identifies what is being requested; it might correspond to a database query’s conditions or to parameters in an API request. The value is the result associated with that key, such as the database record or remote service response.
Common caching options include Redis, Memcached, etcd, and Hazelcast. Redis is often chosen as a general-purpose example, but the broader lesson is to use a cache suited to the system’s requirements rather than assuming that one product is the only possible choice.
Think About It: What repeated operation could a cache avoid in a system that serves the same product information to many customers?
File Storage and Content Delivery
Images, videos, and other files are often better stored in blob storage than in a conventional database. A database is primarily designed to store information that can be queried and organized. A file, by contrast, is often retrieved and served largely as it is, rather than searched internally as a collection of fields.
For example, an online store might need to keep product images and videos, while a video service might need to store large media files. A blob storage service such as Amazon S3 can hold this kind of content.
When users are spread across different regions, delivering every file from one storage location can be slow. A content delivery network (CDN) distributes copies of content across servers in different geographic locations. A nearby server can then serve a user’s request, reducing the distance the content must travel. A common design is therefore to store the original file in blob storage and use a CDN to deliver it efficiently around the world.
Think About It: Why might a CDN improve a user’s experience even when the original image is already stored reliably?
Text Search and Fuzzy Matching
Some systems need to search text rather than retrieve a record by a known identifier. An online store might let customers search product titles and descriptions. A movie service might search titles, genres, or cast members. A map or ride-hailing service might need to match text even when a user’s spelling is imperfect.
Text search engines such as Elasticsearch and Solr support this kind of searching. Both are built on Apache Lucene, which provides core text-search capabilities.
An important feature of text search is fuzzy search: finding likely matches even when the query contains a spelling error. For example, a user might type “AIRPROT” when intending “AIRPORT.” One way to describe the difference between two strings is edit distance: the number of character changes needed to transform one string into the other. In this example, the two letters are interchanged, which can be represented as two character substitutions, giving an edit distance of 2. A search engine can use a chosen level of fuzziness to find likely matches rather than returning no results.
The exact behavior of fuzzy search can involve more than edit distance, but edit distance gives a useful basic picture: the search system tolerates a limited amount of difference between the typed text and a candidate match.
Elasticsearch and Solr should not be treated as the system’s authoritative primary database. A search engine is optimized to find information, but it does not provide the same guarantee that a primary data store provides that persisted data will not be lost. A common design keeps the authoritative data elsewhere and loads a searchable copy into the search engine. This lets the system use the search engine’s strengths without relying on it as the sole source of truth.
Think About It: Why is it useful to separate the authoritative product record from the copy prepared for text search?
Time-Series Data
A time-series database is designed for data whose records are associated with times and whose use follows a time-oriented pattern. Application metrics are a common example: systems may continually record throughput, CPU utilization, or latency.
This workload usually has two notable properties. First, writes are generally append-only: new measurements are added in time order rather than repeatedly changing old measurements. If one record arrives at time T1, later records arrive at times T2 and T3, where T2>T1 and T3>T2. Second, reads often cover a range of time—for example, the last few minutes, hours, or days—rather than retrieving arbitrary individual records or making random updates.
Time-series databases are optimized for these patterns. Examples include InfluxDB and OpenTSDB. They are a natural fit for monitoring and metrics systems because the way the data is written and read differs from many general-purpose database workloads.
Think About It: Why might a database optimized for time-range reads handle monitoring data better than one designed around frequent random updates?
Data Warehouses and Reporting
Operational systems, such as order-processing systems, handle the transactions that keep a business running. A data warehouse serves a different purpose: it gathers large amounts of data so that the organization can analyze it and produce reports.
For example, a company may want to know how many orders it receives, which regions generate the most revenue, or which products are most popular. These questions often involve examining data from across the organization rather than completing one customer’s transaction. Such work is commonly described as offline reporting or analytics.
A system may collect data from several transactional services and place it in a warehouse-oriented environment. Hadoop is an example of technology that can be used in this sort of large-scale data-processing and reporting context. The key distinction is the workload: transaction systems serve operational activity, while analytics systems support broad reporting queries.
Think About It: Why might the system that records a new order have different database needs from the system that calculates sales trends across many orders?
Relational and Non-Relational Databases
The distinction between relational and non-relational databases is a useful starting point when data does not fit one of the specialized cases above.
Structured data and relational databases
Structured data has a consistent organization that can be represented as tables with rows and columns. A user profile, for example, might have fields such as name, email address, city, and phone number. When records follow a predictable schema and need to be queried in organized ways, a relational database can be a good fit.
Relational databases are especially important when operations need strong transactional guarantees. A transaction groups multiple operations so that they behave as a single unit.
Consider transferring money from account A to account B. The system must subtract money from one account and add it to the other. If only one operation succeeds, the account balances become incorrect. A transaction ensures that either both operations happen or neither does.
The database must also provide suitable consistency: after a successful transfer, a subsequent balance query should reflect that transfer rather than sometimes showing an outdated value. Similar needs arise in inventory management. If only one item remains, the system must prevent several simultaneous buyers from all successfully purchasing it.
ACID is the name commonly used for a set of transactional guarantees. The central point here is that a system requiring atomic, consistent transactions should choose a database that provides the guarantees it needs. Relational options include MySQL, Oracle, SQL Server, and PostgreSQL, among others.
Structured data without strong transactional needs
Structured data does not automatically require a relational database. If the application stores information such as user profiles and does not need the transactional guarantees described above, a relational database may still work, but a non-relational database may also be suitable. The choice depends on the data, queries, and scale rather than on the word “structured” alone.
Flexible data and document databases
Some data has many possible attributes, and those attributes vary by item. In an e-commerce catalogue, a shirt might have a size and color, a refrigerator might have a capacity and energy rating, and milk might have a quantity and expiry date.
This information can be represented in a flexible format such as JSON. But if the system must query those varying attributes—for example, find products with particular qualities—storing the information as arbitrary JSON in a relational system may make those queries difficult.
A document database is designed to store flexible records, often called documents, and to support queries over their fields. MongoDB and Couchbase are examples. Search systems such as Elasticsearch and Solr are specialized around text search, even though they also handle document-like data.
A document database is often a candidate when the data has many different attributes or the application must query a variety of those attributes.
Large, growing data with a small set of query patterns
Some systems continually accumulate data while relying on a relatively small number of predictable query types. A location-tracking system is an example: drivers continually send location records, and an important query may be to retrieve the locations associated with a particular driver ID.
This workload may grow as the number of drivers and incoming records increases. In such cases, a wide-column database, also known as a column-family database, can be a suitable choice. It is designed for large data volumes and access patterns that can be anticipated in advance. Cassandra and HBase are examples used for this kind of workload.
The important factor is not simply that the data is large. The fit comes from the combination of growing volume and a limited set of query patterns. If queries are known ahead of time, the data can be organized to serve them efficiently.
When no specialized pattern dominates
If a system has a small dataset, a limited number of straightforward queries, and no strong need for special transactional, document, text-search, or time-series capabilities, several database choices may work. In that case, a specialized database may offer little advantage. Real system designs, however, often combine multiple database types because different parts of the system have different needs.
Think About It: What makes a flexible product catalogue a different database problem from a stream of driver location updates?
Combining Databases in One System
A real application rarely has just one kind of data or one kind of query. Different databases can serve different roles in the same design. The goal is not to force every workload into one database; it is to choose suitable storage for each responsibility and connect those stores carefully.
Orders and inventory in an e-commerce system
Inventory management needs transactional protection. If there is one unit of a product left, only one customer should be able to complete a purchase for it. A relational database can manage active inventory and orders where those transactional guarantees matter.
At the same time, an e-commerce system may accumulate orders continuously. Delivered orders may need to be retained for a long time, including for legal or historical reasons. A design can keep active, undelivered orders in a relational database and move completed historical orders into a system such as Cassandra for long-term storage.
The two databases serve different purposes: the relational store supports current operations that need transactions, while the wide-column store supports a large and growing body of historical data. Moving data between them must preserve the information the system needs; the choice of stores does not eliminate the need for a sound data-flow design.
Reporting across many kinds of product and order data
A report might ask which users bought sugar in the last five days. That question may not correspond to one simple lookup: “sugar” could refer to many individual products, and those products may appear in many orders.
A document database can hold a query-oriented subset of order information, such as a user ID, order ID, order date, and the item IDs and quantities in that order. The document database can be queried to find relevant users and orders. The resulting order IDs can then be used to retrieve fuller order information from the system’s other stores.
This design uses each database for a different task: the document store supports varied reporting queries, while the relational and wide-column stores serve their operational or historical roles. It is an example of combining databases to satisfy several kinds of requirements rather than expecting one database to be optimal for all of them.
Think About It: In the reporting example, why might a system store a query-oriented subset of an order instead of running every report directly against its operational database?
A Practical Decision Process
A simple decision process can organize the choices:
- Identify the data shape. Determine whether the data is consistently structured or varies substantially from record to record.
- Identify the access pattern. Look at how information is written and read: transactions, text search, time-range queries, reporting, or a small set of predictable lookups.
- Identify the scale. Estimate the amount of data and how quickly it grows.
- Check for special requirements. Transactional integrity, fuzzy text matching, geographic delivery, and large-scale analytics all point toward specialized tools.
- Allow multiple databases when workloads differ. One system may need a relational database for transactions, a search engine for text, blob storage for files, and another store for historical or analytical data.
This process is a guide rather than a rule that every application must follow mechanically. The named technologies are examples, not the only valid options. In an actual system, each candidate should be evaluated against the precise requirements and operational constraints.
Comprehensive Review
Database selection is fundamentally about matching a storage system to the job it must perform. Caches reduce repeated database queries or slow remote calls by saving key–value results. Blob storage holds files such as images and videos, while CDNs help deliver those files quickly across geographic regions. Search engines such as Elasticsearch and Solr support text and fuzzy search, but they should not be the sole authoritative source of data. Time-series databases suit append-oriented measurements and reads over time ranges. Warehouses support broad, offline analytics rather than day-to-day transactions.
For general data stores, relational databases are especially useful when the data is structured and operations require transactional guarantees. Document databases can handle records with varied attributes and queries across those attributes. Wide-column databases can suit large, growing datasets with a limited set of predictable access patterns. When one application has several such workloads, combining databases can be more effective than forcing every task into a single store.
The strongest design choice begins by understanding how the data is structured, how the system will access it, and what guarantees and scale the system must support.

Ask anything
We've read this whole study set, so questions about it get the best answers.