{"success":true,"name":"decide-mongodb-write-and-read-concerns-for-data-that-matters","description":"Writing critical data to MongoDB (payments, orders) on a replica set","category":"ai-brimind","path":"ai-brimind/decide-mongodb-write-and-read-concerns-for-data-that-matters/SKILL.md","file":"SKILL.md","content":"---\nname: decide-mongodb-write-and-read-concerns-for-data-that-matters\ndescription: \"Writing critical data to MongoDB (payments, orders) on a replica set\"\n---\n\n# Decide MongoDB Write and Read Concerns for Data That Matters\n\n## When to use\nProject uses MongoDB with replication (Atlas or replica set), and a write is business-critical or a read must see just-written data.\n\n## Example request\nPayment recorded with default settings → default writeConcern majority is usually right, but confirm it wasn't lowered to w:1 for 'speed'. Writing then immediately reading on another connection and missing the data → read preference secondary reads stale replicas; read your own writes from the primary. Bulk analytics import → lower concern is a legitimate trade there; the point is choosing, not defaulting. 'Data disappeared after a failover' → w:1 writes acknowledged by only the primary can be rolled back; majority survives elections. Each maps to 'durability and staleness are settings, and someone must consciously set them'.\n\n## Instructions\nAct as a reliability engineer who never lets critical data ride on unexamined defaults. For each write/read path on replicated MongoDB: (1) classify the data — business-critical (payments, orders, auth) versus tolerable-loss (analytics, caches, logs), (2) for critical writes, confirm writeConcern is majority (the modern default, but verify the connection string and driver options didn't lower it) so an acknowledged write survives a primary failover, (3) for reads that must see a just-completed write, ensure they hit the primary (readPreference primary) or use appropriate readConcern — secondary reads are eventually consistent by design, (4) where you deliberately relax settings for throughput (bulk imports), write the trade-off down next to the code. If replication topology or criticality is unclear, ask before choosing. Only sign off once each critical path's settings are confirmed explicitly, and explain what failure (failover rollback, stale read) the chosen settings actually protect against.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1058\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}