7. MongoDB is a Single-Master System
• All writes are to a primary (master)
• Failure of the primary is detected, and a new
one is elected
• Application writes get an error if there is no
quorum to elect a new master
• Reads can continue
8. Consistency Models
• Relational databases support transactions
• Can only see committed changes
• Commits/aborts span multiple changes
• Read-only transaction flavors
• Read committed, repeatable read, etc
• Single vs Multi-Master
9. Single Master
• All writes go to a single master and then
replicated
• Replication can provide read scalability
• Writing becomes a bottleneck
• Physical limitations (seek time)
• Throughput of a single I/O subsystem
10. Single Master - Sharding
• Partition the primary key space via hashing
• Set up a duplicate system for each shard
• The write-rate limitation now applies to each
shard
• Joins or aggregation across shards are
problematic
• Can the data be re-sharded on a live system?
• Can shards be re-balanced on a live system?
11. MongoDB Storage Management
• Memory-mapped Database files
• Files are (pre)allocated as needed
• Indexes (B*-trees) point to documents
12. Documents
Blog Post Document"
"
p = { author: “sridhar”,"
date: new Date(),"
title: “Using the C# driver with MongoDB”,"
tags: [“NoSQL”, “Mongo”, “MongoDB”]}"
"
> db.posts.save(p)"
19. MongoDB – More
• Geo-spatial queries
• Require a geo index
• Find points near a given point
• Find points within a polygon/sphere
• Built-in Map-Reduce
• The caller provides map and reduce functions
written in JavaScript
20. Scaling MongoDB
• Replication - Read scalability
• Master/Slave
• Replica Sets
• Sharding – Read and write scalability
• Collections are sharded
• Each shard is served by its own replica set
• Shard key ranges are automatically balanced