Database Performance Comparison: AWS RDS Postgres vs Digital Ocean Postgres

Joe Lei
Level Up Coding
Published in
3 min readOct 23, 2019

--

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.

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

Test setup:

AWS: Postgres 11 (2 vCPUs, 4GB RAM, 40GB storage, AWS us-west-1, $68.4/month)

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

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)

Latency:

  • app → AWS: 0ms
  • app → Digital Ocean: 2ms

Custom optimizations: None. Both database instances were tested out of the box with the same data.

How performance was measured:

Method one:

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). This method measured both the query execution time and the network.

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

Example usage:

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

Method two:

I ran explain analyze on a complex query and noted the difference. This method only measured the execution time.

Results:

Method one: query execution + network (2,000 samples)

Average response time:

  • AWS: 145ms
  • Digital Ocean: 233ms

Median response time:

  • AWS: 63ms
  • Digital Ocean: 164ms

Method two: explain analyze results on a complex query (20 samples):

  • AWS: 230ms
  • Digital Ocean: 345ms

Digital Ocean’s response time (query execution + network) was 60% longer on average and 160% by median. The results were fairly consistent using explain analyze; with Digital Ocean being 50% slower.

The app also felt noticeably slower while clicking around. The Medtally app can load pages in as little as 150ms. Adding 100ms to that time would mean 66% slower — a significant difference.

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 datacenter as the app (AWS us-west-1 which is San Francisco). However, this advantage is only 2ms as noted in test setup.
  • AWS Postgres simply uses faster hardware (CPU, RAM, SSD).
  • AWS’s default optimizations just happen to be better for my use case.
  • 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.

Performance issues aside, I really did enjoy using Digital Ocean. 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 more competition in the managed cloud database space.

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

Follow me on Substack: https://joelei.substack.com/

--

--

Full-Stack Engineer. Ex Product Manager. Occasional entrepreneur.