liveBook · Manning

Database

As explained in Grokking Software Architecture

A database is a software system that stores, organizes, and retrieves persistent data.

Data needs somewhere to live after it stops moving through your system. A database stores and retrieves that persistent data—and its design can make an architecture sturdy or turn it into a technical-debt Hydra. section 8.1 section 8.8.3

Choose a database for the job, not for its marketing label:

  • Relational databases such as PostgreSQL and SQL Server support disciplined, structured data and ACID transactions. section 8.1 section 8.10
  • NoSQL databases suit some massive-scale or variable-structure workloads; vector databases support semantic search and AI features. section 8.1 section 8.10
  • Indexes can speed lookups, but add work to every insert, update, and delete. Normalize by default; denormalize or cache when performance targets require it. section 8.10

An ORM can make queries more convenient, but it does not make the database a black box you can safely ignore. Generated SQL, N+1 queries, deadlocks, and slow queries still need to be understood. Use parameterized queries to keep user input data rather than executable SQL, and choose accurate types such as DATE, TIMESTAMP, BOOLEAN, and INTEGER. section 6.8.3 section 8.10

Match the workload

A temporary shopping cart can tolerate lost data and has frequent writes; a billing ledger needs accurate transactions without eventual consistency. A product catalog with variable structure and heavy reads presents a different fit again. section 8.8.3

Listing 12.1 Monolith (The Simple JOIN)
public BlogDetailsViewModel GetBlogDetails(int blogId) #A
{
    try 
    {
        // A single, lightning-fast database query using SQL JOINs
        var blogPost = _dbContext.Posts
            .Include(p => p.Author)
            .Include(p => p.Comments)
            .FirstOrDefault(p => p.Id == blogId);
 
        if (blogPost == null) throw new NotFoundException();
 
        return new BlogDetailsViewModel(blogPost);
    }
    catch (DatabaseException ex) 
    {
        _logger.LogError("Database unavailable."); #B
        throw;
    }
}

See a monolithic blog-details query that uses an ORM to include an author and comments, then handles a missing post and database failure. section 12.7.1

How Grokking Software Architecture covers it

How deep it goes
Explains database tradeoffs, schema design, indexes, data types, and SQL debugging, while stopping short of database administration.
Examples
Uses shopping-cart, billing-ledger, similar-products, and product-catalog workloads, plus an ORM-backed blog query.
What you can do after
Evaluate database choices by workload and diagnose abstraction-related query problems using SQL fundamentals.
How it connects
Connects databases to SQL, NoSQL, vector databases, ORMs, schema design, indexing, ACID transactions, and polyglot persistence.

Also explained in

Compare how 29 books explain database →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.