MongoDB Architecture: A simplified analogy
Single MongoDB Instance:
Library (MongoDB Instance):
Section (Database):
Shelf (Collection):
Books (Documents)
In a single MongoDB instance, you have one library with different sections (databases). Each section has shelves (collections), and each shelf contains books (documents).
MongoDB Replica Set:
Library Chain (Replica Set):
Library 1 (Primary Node)
Library 2 (Secondary Node)
Library 3 (Secondary Node)
Each Library (Node) Contains:
Section (Database):
Shelf (Collection):
Books (Documents)
In a replica set, you have multiple copies of the same library (nodes). Each library/node has identical sections (databases), shelves (collections), and books (documents) to ensure data redundancy.
MongoDB Sharded Cluster:
Library System (Sharded Cluster):
Central Library Catalogue (Config Server):
Librarian’s Desk (Query Router - mongos):
Branch Libraries (Shards):
Library Branch 1 (Shard/Replica Set 1):
Library Branch 2 (Shard/Replica Set 2):
Each Branch Library (Shard) Contains Partial:
Section (Database):
Shelf (Collection):
Books (Documents)
In a sharded cluster, the data (books) is distributed across multiple branch libraries (shards). Each branch library holds a portion of the total data and might be composed of a replica set to ensure data availability. The central library catalogue (config server) knows which books are in which branch library. The librarian’s desk (query router - mongos) directs the visitors (queries) to the correct branch library (shard) based on the catalogue information.
Practical Context:
A Database Instance is like a single library, sufficient for small applications.
A Replica Set is like having multiple identical libraries (or nodes) where if one is closed (fails), you can go to the other without losing any information, ensuring high availability.
A Sharded Cluster is like having several branch libraries for a city, each storing different books to manage the high volume of books and visitors, enabling horizontal scaling

