0
0
MongoDBquery~20 mins

Read from secondaries trade-offs in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Secondary Read Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Read Preference Impact
In MongoDB, what is a primary trade-off when configuring an application to read from secondary replicas instead of the primary?
ASecondary nodes cannot serve any read requests.
BWrites become slower because secondaries handle write operations.
CThe primary node becomes unavailable for reads.
DReads may return stale data due to replication lag.
Attempts:
2 left
💡 Hint
Think about how data replication timing affects read freshness.
query_result
intermediate
2:00remaining
Result of Reading from Secondary with Lag
Given a MongoDB replica set where the secondary is 5 seconds behind the primary, what is the expected behavior when a read query is sent with read preference set to 'secondary' immediately after a write on the primary?
MongoDB
db.collection.insertOne({item: 'book', qty: 10});
// Immediately after, a read with readPreference: 'secondary' is performed
AThe read returns the document only after the secondary catches up, causing a delay.
BThe read returns the newly inserted document immediately.
CThe read fails because secondaries do not accept reads.
DThe read returns an error due to replication lag.
Attempts:
2 left
💡 Hint
Consider how replication delay affects data visibility on secondaries.
optimization
advanced
2:00remaining
Optimizing Read Latency with Secondary Reads
Which strategy best reduces read latency when using secondary reads in a geographically distributed MongoDB replica set?
AConfigure read preference to 'nearest' to read from the closest secondary node.
BAlways read from the primary to ensure data freshness.
CDisable replication to avoid lag.
DUse read preference 'primaryPreferred' to read only from the primary.
Attempts:
2 left
💡 Hint
Think about how network distance affects latency.
🔧 Debug
advanced
2:00remaining
Diagnosing Stale Data Reads
An application reads from secondaries but notices stale data frequently. Which MongoDB feature can help reduce stale reads without sacrificing availability?
ADisable secondary reads and read only from primary.
BIncrease write concern to 'w: 0' to speed up writes.
CUse 'readConcern' set to 'majority' to ensure data is acknowledged by most nodes.
DSet read preference to 'primaryPreferred' to always read from primary.
Attempts:
2 left
💡 Hint
Consider how read concern affects data consistency.
🧠 Conceptual
expert
2:00remaining
Trade-offs of Reading from Secondaries in High Write Workloads
In a MongoDB replica set with heavy write traffic, what is a key trade-off when enabling reads from secondaries to scale read throughput?
ASecondary nodes reject all read requests to maintain consistency.
BIncreased risk of reading outdated data due to replication lag, but improved read scalability.
CWrites become slower because secondaries handle write operations.
DPrimary node becomes a bottleneck for all reads and writes.
Attempts:
2 left
💡 Hint
Think about how replication lag affects read freshness and system scalability.