Cosmos DB Architecture
1. Cosmos DB Architecture
Welcome back! In this video, we'll explore Azure Cosmos DB, Microsoft's fully managed, globally distributed NoSQL database service.2. Azure Cosmos DB
We'll go through how it helps developers build highly responsive applications with massive scalability, and how to use it with SDKs and APIs in your own projects.3. The problem
Cipher Coffee's customer base has gone global. From Seattle to Singapore, every online order, loyalty point, and customer profile must be stored and synced quickly. A single central database would make distant users wait longer, like customers standing in one checkout line at the only open register. Cosmos DB solves this by adding regional replicas, so each user is served locally, while data syncs automatically behind the scenes.4. What is Cosmos DB?
Azure Cosmos DB is a multi-model, globally distributed NoSQL database, meaning a more flexible database, like a folder where you can store documents of different shapes and sizes, unlike traditional SQL databases like a spreadsheet with rigid columns and rows. CosmosDB supports multiple APIs and data types. Think of it as a flexible restaurant menu: you can choose your preferred API flavor: SQL (Core) for querying JSON documents, MongoDB API for Mongo developers, Cassandra for wide-column storage, Gremlin for graph relationships, and Table API for simple key-value data. It’s all powered by the same globally distributed, low-latency engine.5. Cosmos DB for developers
Cosmos DB is designed with developers in mind. It offers automatic indexing, so you don't need to manage complex schemas. Every property in your data is indexed by default, which means queries run fast without requiring you to define indexes upfront, Cosmos DB handles it automatically. It provides five consistency levels: from Strong to Eventual, giving you control over performance and data accuracy. Think of consistency like communication in a team: Strong means everyone hears the same message instantly. Eventual means everyone catches up eventually - faster performance, less overhead. More on this later.6. Scaling and Throughput (RU/s)
Cosmos DB uses Request Units per second, or RU/s, to measure performance, like energy points you spend for database operations. Each read, write, or query consumes some RU/s. You can provision a set amount or let autoscale adjust it dynamically.7. Scaling and Throughput (RU/s)
Cipher Coffee uses autoscale to handle peak hours, like having extra baristas come in when the morning rush hits, and fewer during quiet afternoons.8. Elastic scale and Partitioning
So how does CosmosDB scale? The magic that makes this work is partitioning. When you create a container to hold your data (like a table), you choose a partition key. This key tells Cosmos DB how to group your data. For example, Cipher Coffee could use customerId as the partition key for their orders. All orders for a single customer are now stored together. When a customer requests their order history, Cosmos DB knows exactly where to look, keeping queries fast no matter how large the database gets. However, choosing the right partition key matters, if some customers place disproportionately many orders, this can create uneven partition load, known as a "hot partition," which can slow down performance.9. Global distribution
Cosmos DB makes global data replication as easy as ticking checkboxes. You can replicate your database to any Azure region with just a few clicks. If one region goes down, traffic automatically reroutes, high availability and minimal data loss when multi-region writes are enabled. It's like having a backup cafe ready to serve customers instantly if the main branch closes for maintenance.10. Monitoring and cost optimization
Developers can monitor performance directly in the Azure Portal with metrics: RU/s consumption, latency, and request charge. It's like checking your car's dashboard: you can see how fast it's running and how much fuel you're using. By analyzing these metrics, Cipher Coffee's engineers identified underused databases and reduced costs by adjusting throughput dynamically.11. Let's practice!
Now, let's get hands on!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.