- Newest
- Most votes
- Most comments
It's not 100% clear from your question how your network is structured.
In general, there is no latency difference between access between EC2 instances in a single VPC vs. EC2 instances in peered VPCs. (For an explanation of why that is, see this re:Invent video on YouTube. Note that it does not matter if the peered VPCs are in different accounts.
However, traffic between availability zones will always incur a latency penalty (because the speed of light is finite). if lowest possible latency is desired then hosting the application components in the same AZ is the best way to go. The latency between availability zones is measured in single-digit milliseconds (see the documentation for more information) but it is still latency and it adds up.
If you are seeing higher latency you should do a deep-dive on where the latency is being introduced - not all of it will come from the network; there may be other bottlenecks in the database or application.
Relevant content
- Accepted Answerasked 4 years ago
- Accepted Answerasked a year ago
- asked 5 years ago
- asked a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
Have you compared the latency to the same queries originating in the same VPC as the Peered MongoDB ? You can eliminate the peering network connection latency that way. Rule of thumb, you should see around 1 or 2 ms between AZs in the same region due to a peering connection.
Yes, as mentioned in the post as well, if there are two different ec2 instance, one is the API server and one is the mongodb server in the same VPC. I'm getting a latency of 3ms for querying one document and. 20ms for querying 100 objects. So peered connection in the same region is taking 4 times longer to respond to the same nature of query.