Database / CouchDB Interview Questions
What is the _node and _cluster_setup API used for in CouchDB clustering?
The _node and _cluster_setup APIs are the two primary endpoints for managing a CouchDB cluster's topology. They are distinct in scope: _node operates on individual node configuration, while _cluster_setup orchestrates the multi-step process of forming or extending a cluster.
The _node API (/_node/{node-name}/) provides per-node operations:
GET /_node/_local/_config— read the running configuration of the local node.PUT /_node/_local/_config/{section}/{key}— change a configuration value live without restart.GET /_node/_local/_stats— performance counters for the local node.GET /_node/_local/_system— Erlang VM stats (memory, processes, ports).
The _cluster_setup API (/_cluster_setup) provides a guided wizard for cluster formation:
# Step 1: Enable cluster mode on node 1
curl -X POST http://admin:pass@node1:5984/_cluster_setup \
-H "Content-Type: application/json" \
-d '{"action":"enable_cluster","username":"admin","password":"pass",
"node_count":3,"bind_address":"0.0.0.0","port":5984}'
# Step 2: Add node 2 to the cluster
curl -X POST http://admin:pass@node1:5984/_cluster_setup \
-H "Content-Type: application/json" \
-d '{"action":"add_node","username":"admin","password":"pass",
"host":"node2","port":5984}'
# Step 3: Finish cluster setup
curl -X POST http://admin:pass@node1:5984/_cluster_setup \
-d '{"action":"finish_cluster"}'
# Check cluster membership
curl http://admin:pass@localhost:5984/_membership
After cluster formation, GET /_membership returns the list of all nodes in the ring. Nodes are identified by their Erlang node name, typically couchdb@hostname. The _node/_local shortcut always refers to the node receiving the request, which is convenient in scripting.
More Related questions...