Postgresql – Load balancing postgresql db servers on aws

amazon-web-servicespostgresql

I am running a block chain node (for those who don't know, blockchains essentially keep db instances in sync via a consensus protocol). For now I have a web server that talks directly to the db inside of the node.

However, in anticipation of higher load, I would like to put a load balancer in front of the db (so that I can add more nodes as I like behind the balancer and scale that way).

I am hosting the node on AWS (just an EC2 instance). I was hoping I could just add an AWS class load balancer in front of the EC2 instance but can't find any tutorials on how to to this.

Question: Can this be done (in some form) and how can I get this done. Again, the objective is to have a single connection string that my web service layer can connect to which, behind the scenes, will route the request to several db instances.

Thanks in advance.

Edit: Basically, just assume that I have several db instances that are all being kept in sync by the blockchain network. I only need perform reads on the instances (writes are submitted to the network for consensus before being committed to the db via the protocol). I need to find a way to balance reads across several instances (which, again, are guaranteed to be in sync).

Best Answer

Load balancing databases is more difficult than load balancing say stateless web servers. You can't automatically load balance a database using AWS features. The primary way to increase database performance is to use a larger instance or to allocate more I/O capacity.

Amazon RDS has the concept of a "read replica". These use native replication to keep one more more additional databases in sync with the master. Your application has to be smart enough to use the correct database, master for writes or a replica for reads.

You're going to have to do some reading of your own to understand database architectures, and how it will interact with your use case. You haven't told us enough to give you a definitive answer. This article tells you about PostgreSQL clustering and such.

I suggest you scale up to a larger instance as your first step, having multiple clients use that database. Next you will have to scale out and somehow keep the databases in sync.

On AWS you could rewrite your application to use DynamoDB, a highly scalable no-sql database. That tends to be a huge change.

If you edit your question to give more detail about what you're doing you may get more help.