loading...
Cover image for Performance Review: AWS RDS Postgres vs Digital Ocean Postgres

Performance Review: AWS RDS Postgres vs Digital Ocean Postgres

jlei523 profile image jlei523 ・3 min read

When Digital Ocean announced the availability of a managed Postgres database service, I wanted to answer this question:

Would my app’s performance improve if I switched my Postgres instance from AWS to Digital Ocean?

I'm working on Medtally.com, a data-driven medical community. Because nearly every page on Medtally requires fresh data, the speed of the database is crucial to providing a fast experience for users.

medtally

Example page on Medtally. Every page request pulls data from a Postgres database.

Thanks to the generosity of Digital Ocean's Hatch program, I was able to get some free credits to run a test.

Test setup:

AWS (original): Postgres 11 (2 vCPUs, 4GB RAM, 40GB storage, AWS us-west-1)

Digital Ocean: Postgres 11 (2 vCPUs, 4GB RAM, 38GB storage, SFO2)

App hosting: Zeit Now v1 (SFO, AWS us-west-1)

App stack: Express.js, React.js, Next.js (read my tips on building with Next.js)

How performance was measured:

To measure performance as close to the real-world as possible, I tracked the response time of a common query required to fetch data for our popular health condition pages (example).

I used Node.js' perf_hooks API and logged the results.

Here's the example code I used:

const { performance } = require('perf_hooks');
const t0 = performance.now(); //start timer
const data = await fetchDataFromDB(id);
const t1 = performance.now(); //end timer
const responseTime = t1 - t0 //responsetime in ms

Results after ~2,000+ samples:

Average response time:

  • AWS: 145ms
  • Digital Ocean: 233ms

Median response time:

  • AWS: 63ms
  • Digital Ocean: 164ms

Digital Ocean's response time was 60% longer on average and 160% by median.

The app felt noticeably slower while I clicked around. The Medtally app can load pages in as little as 150ms. Adding 100ms to that time would mean 66% slower - a significant increase.

I was surprised. I expected the performance to be much closer since both databases had the same number of CPUs, RAM size, and disk size.

Some possible reasons why AWS was faster:

  • The AWS Postgres instance had an advantage in latency because it was hosted in the same physical location as my app (AWS us-west-1 which is San Francisco). However, Digital Ocean's database was also hosted in San Francisco and so the difference should have been negligible and should not have been a 100ms.

Update: The difference is only 2ms after I ran a few pinging tests between the AWS us-west-1 and Digital Ocean SFO2. We can rule this reason out.

Note: I could have eliminated latency as a variable in the test by basing the conclusion on query execution times in pg_stat_statements instead. I did not have enough time to do this but I may revisit in the future.

  • AWS Postgres simply uses faster hardware (CPU, RAM, SSD).

  • Digital Ocean's managed Postgres service is new and the company needs more time to optimize its performance. AWS RDS has been in service for 9 years compared to less than a year for Digital Ocean.

Back to AWS RDS

I will be sticking with AWS RDS until Digital Ocean improves its performance.

Besides the performance issues, I really did enjoy using it. The UI/UX is far superior to AWS and so is the documentation. I have high hopes for it in the future and we could use some strong competition in managed database hosting.

With that said, Medtally.com is back to using AWS RDS.


Interesting in connecting with me? You can find me on Twitter.

Posted on by:

jlei523 profile

jlei523

@jlei523

Creator @ http://Medtally.com, a new way for patients to connect and share. Also made http://truehome.hk. Ex @Redfin & @Rocketlawyer

Discussion

markdown guide