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




























