I want to integrate CNPG operator to my k8s cluster, but have several questions, I tried to find answers on the web, but couldn't, so decided to ask them here.
My team needs HA Postgres cluster with auto-failover, as CNPG could provide. But, moreover, team of developers needs some consistency guarantee: reads after writes. That means, that when response on some write requests returns, all next reads must see this write (or later one). When the PG is running in single instance manner, it is guaranteed. When it is running in primary-replica mode, guarantee could be achieved by remote_apply
and synchronous_standby_names
settings. But if I choose to use all names in synchronous_standby_names
setting, cluster will lose it's HA status, because fail of single pod will cause refusing write queries of entire system.
So, Postgres configuration allows, and CNPG configuration allows to use quorum replication for these purposes: we can wait only for k of n replicas to answer to primary. But, than, the question is: can we load balance read queries on standby replicas, as CNPG does? CNPG creates 3 k8s services (-rw for read and writes leading to primary, -ro for read only leading to replicas, -r for read leads to replicas and primary because all of them can handle reads).
So, what if service send my query to replica, that wasn't in quorum on previous write? Is it possible, or CNPG makes something to avoid this behavior, and my application can use all replicas for reads using -r
or -ro
services? Or maybe connection pooler may balance queries on right replicas? (I tried to find out it on web, but couldn't)
I need to answer these questions to choose architecture to build in our platform. If you have some advice on my situation, will be glad to listen to you!
Tried to find this info on web, or in documentation, but all of the links were talking about work of synchronous commit without needed info about quorum corner cases.