An application is experiencing high latency during bulk inserts. The DBA notices that the application uses a default write concern and acknowledges every write before proceeding. Which strategy should be implemented to improve write throughput while ensuring data safety?
Trap 1: Disable the oplog on the secondary members to remove replication…
Disabling the oplog is impossible as it is a fundamental component of the replica set architecture required for replication and recovery. Removing it would break the cluster and prevent data synchronization between members, making high availability impossible for your production application environment.
Trap 2: Use an unacknowledged write concern (w: 0) for all application…
Using w: 0 provides no error feedback to the application if a write fails, leading to potential data loss without notification. While it offers the highest performance, it is risky for application integrity and prevents the driver from catching duplicate key errors or connectivity issues.
Trap 3: Increase the number of secondary nodes to distribute the write load.
Adding secondary nodes does not increase write capacity because all writes must still be directed to the primary node. Increasing the number of replicas actually increases the replication load on the primary, potentially decreasing write throughput rather than improving it in a standard configuration.
- A
Disable the oplog on the secondary members to remove replication overhead.
Why it fails: Disabling the oplog is impossible as it is a fundamental component of the replica set architecture required for replication and recovery. Removing it would break the cluster and prevent data synchronization between members, making high availability impossible for your production application environment.
- B
Use an unacknowledged write concern (w: 0) for all application operations.
Why it fails: Using w: 0 provides no error feedback to the application if a write fails, leading to potential data loss without notification. While it offers the highest performance, it is risky for application integrity and prevents the driver from catching duplicate key errors or connectivity issues.
- C
Change the write concern to 'w: 1' to allow the primary to acknowledge immediately.
Setting w: 1 allows the primary to acknowledge the write immediately after processing it locally, without waiting for secondary replication. This reduces latency significantly while still ensuring the primary has successfully committed the data to its own journal and memory, balancing throughput and data reliability.
- D
Increase the number of secondary nodes to distribute the write load.
Why it fails: Adding secondary nodes does not increase write capacity because all writes must still be directed to the primary node. Increasing the number of replicas actually increases the replication load on the primary, potentially decreasing write throughput rather than improving it in a standard configuration.