Mongo Architecture

0.0(0)
Studied by 1 person
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/9

encourage image

There's no tags or description

Looks like no tags are added yet.

10 Terms

1
New cards

Describe how a query travels through MongoDB's internal execution layers (Query Layer, Data Model Layer, Storage Layer). What specific role does the WiredTiger storage engine play at the end of this pipeline?

  • Query Layer: The query analyzer inspects the shape of the query, selects the optimal index, caches the query shape and index choice, and forwards the annotated request to the next layer.

  • Data Model Layer: Translates the query layer request into a discrete set of documents to retrieve using its understanding of indexes, then passes the record locations down to the storage layer.

  • Storage Layer (WiredTiger): Translates data model requests into specific record offsets to load directly from disk into memory if they are not already cached. WiredTiger serves as the underlying physical storage engine handling low-level record reading and writing.


2
New cards

Define Latency and Throughput in the context of MongoDB architecture. How does MQL (MongoDB Query Language) contribute to the database's Usability?

  • Latency: The total time required by the database to process and service a single application request.

  • Throughput: The total volume of database operations processed per unit of time.

  • Usability via MQL: MQL enhances usability by providing an intuitive, expressive query interface for application developers to interact with the database.


3
New cards

What is the maximum number of nodes permitted in a single replica set, and how many of those nodes can participate in elections as voting members? Why must voting members be distributed carefully across data centers?

  • Node & Voting Limits: A replica set can hold between 2 to 50 nodes, but a maximum of 7 members can vote in elections.

  • Voting Distribution: Voting members must be geographically distributed across data centers so that a majority (at least 4 members) survives a single data center outage to successfully elect a new primary.


4
New cards

Differentiate between a writeConcern of "majority" and a readConcern of "majority". How do these settings enforce data durability and read safety across nodes?

  • writeConcern: "majority": Ensures write operations are persisted to a majority of data-bearing nodes in the replica set before returning a success acknowledgement to the application.

  • readConcern: "majority": Guarantees that the query returns data that has been written to and committed by a majority of nodes, preventing reads of uncommitted or stale data.


5
New cards

Explain the distinct responsibilities of mongos and the Config Server Replica Set within a sharded cluster. How does the driver select which mongos instance to interact with?

  • mongos Router: Acts as a query router for client applications, directing read and write operations to the correct shard(s).

  • Config Server Replica Set: Stores and manages cluster metadata, acting as the authoritative source for sharding state.

  • Driver Selection: The MongoDB driver selects a mongos router from its seed list by picking one at random from those with the lowest network latency.


6
New cards

Explain what happens when the Primary node suffers an equipment failure. What mechanism provides High Availability, and what is the typical failover duration?

When the Primary node fails, the remaining nodes hold an automatic election to select a new Primary. Automatic failover provides High Availability, with typical failover completing in 5 seconds or less

7
New cards

Why is MongoDB's High Availability mechanism described as "fast failover" rather than "Active-Active"?

It is termed "fast failover" rather than "Active-Active" because only one Primary node accepts writes at any given time, while Secondary nodes maintain replicated copies and take over via rapid election when the Primary drops offline.

8
New cards

A database team is partitioning a collection named user_data using the shard key { x: 1 }

Define what a chunk is in MongoDB sharding. Given a continuous key space for x ranging from { x: minKey } to { x: maxKey }, explain how documents are assigned to chunks and how the database manages these chunks across shards.

A chunk is a contiguous range of shard key values within the overall key space. Every document is assigned to a specific chunk based on its shard key value. MongoDB automatically balances these chunks across the shards in the cluster to maintain even data distribution.

9
New cards

An enterprise application expects its dataset to grow from 200 GB to 10 TB over the next year, while concurrent write traffic is projected to increase tenfold. Should the team deploy Replica Sets or Sharding to accommodate this growth? Justify your answer based on the explicit architectural use cases of replication versus sharding.

The team should deploy Sharding. Replication is intended for high availability and read latency reduction—it does not scale storage capacity or write performance. Sharding provides horizontal scaling, allowing datasets and write throughput to distribute across multiple physical machines.

10
New cards

Scenario D: Operational Query Routing

Context: An application issues two queries through a mongos router:

  1. db.users.find({ country: "US" }) where country is the shard key.

  2. db.users.find({ age: 30 }) where age is not part of the shard key. How does mongos handle routing for each of these two query requests based on shard key usage?


  1. For db.users.find({ country: "US" }), mongos uses the shard key (country) to target and route the query directly to the specific shard(s) hosting the matching chunk.

  1. For db.users.find({ age: 30 }), mongos cannot determine which chunk holds the data without the shard key, so it must scatter-gather the query by broadcasting it across all shards in the cluster.