0

I understand how to deploy something like MySQL in a Statefulset, configure replication between the replicas, and how to connect my application to one of the replicas; connect to the primary pod for writes and any pod for reads. Basically, everything in How to Connect Golang application to mysql statefulset in Kubernetes.

So in my application, does that mean I need two connections? One connection for writes and one for reads?

When creating more replicas of my application, how do I manage concurrent connections to the database? Each application pod is connecting to the primary MySQL pod for writes so I sense that there could be data races. Is this something my application has to manage? Or does the database manage it? Or are there proxies designed for this depending on the database?

Shadow
  • 33,525
  • 10
  • 51
  • 64
atye
  • 87
  • 1
  • 13
  • You can use the connection to the primary for reading and writing, the rest can only be used for reading. Any particular application only needs one connection, going to the appropriate server depending on what it will do. – Barmar Jul 29 '23 at 20:34
  • @Barmar The application will be writing and reading. My confusion is how each application will do this without any data races. It's a real-time application and could require a write or a read depending on the request. – atye Jul 29 '23 at 20:48
  • That's what transactions are for. – Barmar Jul 29 '23 at 20:48
  • Ok, I understand that as the database will handle concurrent transactions from the applications. – atye Jul 29 '23 at 20:59

0 Answers0