{"type": "session", "harness": "opencode", "id": "sys-0034", "name": "MongoDB Client-Side Replication Monitoring"} {"type": "message", "message": {"role": "system", "content": "You are an expert software engineer."}} {"type": "message", "message": {"role": "user", "content": "How does MongoDB monitor replica set health?"}} {"type": "message", "message": {"role": "assistant", "content": "MongoDB uses SDAM (Server Discovery and Monitoring) protocol:\n\nStreamableReplicaSetMonitor:\n- Inherits ReplicaSetMonitor + TopologyListener\n- getHostOrRefresh()/getHostsOrRefresh() returns hosts matching ReadPreference\n- getPrimaryOrUassert() returns current primary\n- failedHost() marks host as failed\n\nReplicaSetMonitorManager:\n- Global registry of ReplicaSetMonitor instances\n- One monitor per replica set name\n\nReplicaSetChangeNotifier:\n- Notifies subscribers of topology changes\n- Decouples monitoring from connection pooling\n\nServer selection flow:\n1. Application needs connection\n2. Consults ReplicaSetMonitor for topology\n3. Filters by ReadPreference (primary, secondaryPreferred, nearest)\n4. Selects server based on latency window\n5. Returns connection from pool"}}