16 Cosmos DB, CQRS, and other database types

 

This chapter covers

  • Introducing NoSQL databases and how they differ from relational databases
  • Exploring the features that the NoSQL database called Cosmos DB
  • Performance-tuning the Book App using EF Core Cosmos DB database provider
  • Considering the differences between and limitations of using Cosmos DB with EF Core 5
  • Knowing what issues you might hit when swapping from one database type to another

The Book App has been a constant theme throughout this book, and up until now, it has used an SQL Server database to store the books data. In this chapter, we are going to performance-tune the Book App by combining the original SQL Server database with another database called Cosmos DB. In chapter 14, we performance-tuned the Book App to handle 100,000 books. In this chapter, we take the number of books to 500,000 with the same or better performance by using Cosmos DB. Cosmos DB is relatively new (it came out in 2017), and some readers won’t have used it yet. So in addition to using this database to improve performance and scalability, I point out the differences between Cosmos DB, which is a NoSQL database, and the more traditional relational databases such as SQL Server.

16.1 The differences between relational and NoSQL databases

16.2 Introduction to Cosmos DB and its EF Core provider

16.3 Building a Command and Query Responsibility Segregation (CQRS) system using Cosmos DB

16.4 The design of a two-database CQRS architecture application

16.4.1 Creating an event to trigger when the SQL Book entity changes

16.4.2 Adding events to the Book entity send integration events

16.4.3 Using the EfCore.GenericEventRunner to override your BookDbContext

16.4.4 Creating the Cosmos entity classes and DbContext

16.4.5 Creating the Cosmos event handlers

16.5 Understanding the structure and data of a Cosmos DB account

16.5.1 The Cosmos DB structure as seen from EF Core

16.5.2 How the CosmosClass is stored in Cosmos DB

Summary