Are managed databases (e.g. Amazon RDS) slower to access than database in the same machine (EC2) as web server
Imagine two cases:
- I have web server running in an EC2 instance and it is connected to the database in the RDS, the managed database service.
- I have web server and database running in the same EC2 instance.
Is my database in RDS going to be slower to access because it's not in the same machine?
How many milliseconds, approximately, does it add to your latency between the two?
Does this become bottleneck?
What about other managed database services like Azure, GCP, Digital Ocean, etc? Do they behave the same?
Managed databases are supposed to be accessed via network. And yes it is true that your system will have latency if your database is on a network. But this latency depends on provider and network you're working on. When you use services from different providers, the latency is high. When you are using the services by single provider (say aws), it reduces. Best results are achieved when the servers are physically as close as possible say in single region. You need to benchmark these and see for yourself if the latency works for you.
On the other note, I've never encountered this latency affecting performance of my application. I've been using RDS instances since fairly long time to say I never had second thoughts about having db in same EC2 instance. With Go under the hood and Postgers RDS instance, my health check http requests fall under 20ms response time. Let me tell you that this is health check is also checking a SELECT 1
query success on db.