Suppose we're using Kubernetes
Deployments
to host MongoDB.
I know that Deployments suppose their pods are identical, and the corresponding service divides requests between the pods regardless of which pod is which.- Does this yield data inconsistency?
- Or will mongo be run in its Replication manner, where one pod becomes Primary (& accepts write/read requests) and others become Secondary (& answer read requests).
Suppose we're using Kubernetes
StatefulSets
to host MongoDB.
Naturally, there's a service dividing request between stateful pods.
Now in my application server, should I manually send Write requests to the Primary node? Or will it be handled by MongoDB itself? If so, how does MongoDB keeps the consistency? Where do the stateful pods get notified about each other and by who?
I suppose one scenario would be that my request gets sent to any pod randomly, If that pod can handle it (i.e. read request), it will do so. Otherwise (write request), the pod will send the request to the Primary Pod.
But that seems slow and inefficient and slow, doesn't it? Sending requests randomly hoping they would reach the correct place on the first try.