Mercado Tech Brasil

Choose the right database in solutions architecture: compare the types

Published on · Solutions Architecture · by William Garcia

File drawers organized in an old cabinet
Photo: Topher · WordPress Photo Directory (CC0, public domain)

This is article 6 of 10 in the Mercado Tech Brasil series on solutions architecture. Every solution stores information somewhere, and choosing the database is one of the hardest decisions to undo later. That is why it is worth understanding the options before going with whatever tool the team already knows.

The relational database: the default choice

Relational databases organize data in tables with defined columns and relationships between them, queried with SQL. They offer reliable transactions: either all the operations in a set are saved, or none are. That is essential when an order, its items and the stock reservation need to stay consistent.

They are the natural choice for master data, orders, contracts and any structured data with integrity rules. The products are mature, many people know how to run them, and they scale further than many imagine, with well-designed indexes, read replicas and partitioning.

When a NoSQL database makes sense

NoSQL is an umbrella for models other than the relational one, each optimized for a type of use:

  • Documents: store flexible records in a JSON-like format. Good for product catalogs whose attributes vary a lot.
  • Key-value: fetch a value from a key, quickly. Good for sessions, preferences and caching.
  • Wide-column and high-volume: built for heavy, distributed writes, such as event logs.
  • Time series: optimized for measurements over time, such as sensor data and metrics.
  • Graphs: highlight relationships, such as referral networks or routes.

Flexibility has trade-offs: fewer transaction guarantees across records, more limited queries and integrity rules that become the application's responsibility.

How to choose a database in solutions architecture

  • How will the data be read? Varied queries and reports favor the relational model; access always by the same key favors key-value.
  • What is the read-to-write ratio, and what volume is expected?
  • What level of consistency does the business require?
  • Does the team know how to run the technology in production, with backup, restore and monitoring?

You do not have to pick a single model. The same solution can use a relational database for orders and a search engine for the catalog. Just be careful not to multiply technologies without need, because each one adds operational effort.

Who owns the data in solutions architecture

In architectures with multiple services, each one should own its data. When everyone reads and writes directly to the same tables, any change becomes a negotiation between teams. Share data through APIs or events.

Caching: speed with an expiration date

A cache is a fast copy of frequently requested data, such as an e-commerce storefront. It takes load off the database, but you must decide how long a piece of information can be stale and how to invalidate it when it changes. Price and stock, for example, tolerate much less delay than a product description.

Versioned schema changes

Schema changes should be made through migrations versioned alongside the code, tested and reversible whenever possible. Object-relational mapping tools help productivity, but they do not replace knowing the queries they generate.

In practice

In automation projects, I usually start with the relational database the company already runs well and add another model only when a concrete requirement calls for it. I also review, together with the privacy team, which personal data needs to be stored and for how long, because the best data to protect is the data that never needed to be stored.

Read also: Ensure scalability and availability in solutions architecture: learn how

Translated from the original in Portuguese. Read the original.