Struggling with Load Balancer Configuration for High Traffic Websites

Hey everyone,

I’ve been using DigitalOcean for hosting several of my projects, and I’ve recently run into some issues configuring load balancers for a high-traffic website. Here are the details of my setup:

  • Droplets: 4 web server droplets running Ubuntu 22.04 LTS
  • Database: 1 Managed PostgreSQL database
  • Load Balancer: DigitalOcean Load Balancer with SSL termination
  • Traffic: Peak traffic is around 50,000 requests per minute
  • During peak traffic times, I’m experiencing slow response times and occasional timeouts. The load seems to be distributed across the droplets, but performance isn’t as smooth as I’d hoped. Here are a few specific issues I’ve noticed:
  1. Slow SSL Handshake: Sometimes, the SSL handshake takes a considerable amount of time.
  2. Database Latency: There seems to be increased latency in database queries under high load.
  3. Session Management: I’m using sticky sessions, but occasionally users are being redirected to a different droplet, causing session loss. My Website: FESCO Online Bills that website to check fesco bills online

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
July 2, 2024

Hi there,

As this is only happening during peak traffic times, there are a few things that I could suggest here:

On the backend Droplets side:

  • Make sure that your backend services have enough resources to handle the incoming traffic. You can either use the DigitalOcean monitoring graphs to take a quick overview of your resource utilization and also follow the steps here on how to find which processes are consuming most of the resources on your server by following the steps here:

  • Once you are able to pinpoint the services consuming most of the resources you could either plan for an upgrade or try to optimize those services, but this would depend on the above findings.

On the database side:

  • Again make sure that the database cluster has enough resources to handle all of those 50,000 requests per minute. You might want to consider scaling up if there aren’t enough resources.
  • Go through your query log and see if there are any particular queries that are slow here. You can follow the the steps on how to do that here:

  • Sometimes adding a few indexes can drastically improve the performance of such slow queries.

  • If you have a lot of read operations, you could plan on scaling horizontally by adding some read replicas and configuring your app to use the read replicas for all or some of your read queries, that way you will reduce the load on the primary server which will only handle the writes. Depending on the framework that you are using this might be easily configurable, for example, Laravel offers this out of the box.

On the sessions side:

  • Rather than solely relying on the sticky sessions, you could introduce a centralized sessions store for all of your Droplets. Consider using an external session store a managed Redis instance to manage sessions centrally. This can help avoid session loss when users are redirected to different Droplets.

On the load balancer side:

  • To reduce the overall latency and load on the load balancer itself, what you could do here is to use a CDN service like Cloudflare. This will not only be beneficial if your website serves a lot of static content, but will in general reduce latency for users by serving content from edge locations.

Hope that this helps!

- Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel