Table of Contents
Core Concepts: Peering vs. Hub-and-Spoke
VPC Peering creates a direct network path between two VPCs. It behaves as if the instances are on the same local network. There is no central appliance, meaning there is no single point of failure and no additional latency introduced by an intermediate hop. AWS Transit Gateway acts as a regional network transit hub. It allows you to connect VPCs, SD-WANs, and on-premises environments via a single gateway. It functions as a Layer 3 router, managing traffic flow between all "attachments" through centralized route tables.Detailed Comparison Table
The choice between these two services usually hinges on two factors: the number of VPCs and the volume of data transferred.| Feature | VPC Peering | AWS Transit Gateway |
|---|---|---|
| Performance | Lowest latency (no extra hop) | Slightly higher (additional hop) |
| Scalability | Hard to manage (Mesh topology) | Easy (Hub-and-spoke) |
| Data Processing Cost | $0.00 per GB | $0.02 per GB (standard) |
| Hourly Cost | Free | ~$36/month per attachment |
| Max Connections | 125 active peerings per VPC | Up to 5,000 VPCs per Gateway |
| Routing Complexity | High (Individual route entries) | Low (Centralized tables) |
When to Choose VPC Peering for Microservices
VPC Peering is the superior choice for high-throughput, latency-sensitive microservices. If your application relies on sub-millisecond responses between services in different VPCs, the direct path of peering ensures that AWS's software-defined network stays out of your way. Because there is no "gateway" instance, VPC Peering scales horizontally. There are no bandwidth bottlenecks. While Transit Gateway supports up to 50 Gbps per VPC attachment, VPC Peering is only limited by the instance's network interface capabilities (up to 200 Gbps on modern Nitro instances). To create a peering connection via the AWS CLI:# Create the peering request
aws ec2 create-vpc-peering-connection \
--vpc-id vpc-1a2b3c4d \
--peer-vpc-id vpc-5e6f7g8h
# Accept the peering request (in the same or different account)
aws ec2 accept-vpc-peering-connection \
--vpc-peering-connection-id pcx-11223344556677889
You should opt for VPC Peering when:
You have fewer than 10 VPCs that need to communicate.
You are running data-intensive workloads (ETL, Big Data) where the $0.02/GB fee is prohibitive.
You need the absolute lowest latency possible for synchronous microservice calls.
When to Choose Transit Gateway for Enterprise Scale
As organizations scale to hundreds of VPCs across multiple accounts, VPC Peering becomes a management nightmare. Each new VPC requires N-1 peering connections to maintain a full mesh. This leads to thousands of routing table entries that are difficult to audit or secure. AWS Transit Gateway solves this by centralizing all connectivity. It supports transitive routing, meaning VPC A can talk to VPC C through the Gateway without a direct link. This is impossible with VPC Peering. Below is a Terraform snippet demonstrating how to attach a VPC to a Transit Gateway:resource "aws_ec2_transit_gateway_vpc_attachment" "example" {
subnet_ids = [aws_subnet.private_a.id, aws_subnet.private_b.id]
transit_gateway_id = aws_ec2_transit_gateway.main.id
vpc_id = aws_vpc.microservice_vpc.id
tags = {
Name = "Microservice-TGW-Attachment"
}
}
Use Transit Gateway if:
You use a "Shared Services" VPC (for logging, DNS, or security scanning) that dozens of other VPCs must access.
You need to inspect traffic between VPCs using a centralized firewall appliance.
You need to connect multiple VPCs to an on-premises data center via a single Direct Connect or VPN.
Final Decision Matrix
The "Tipping Point" usually occurs when management complexity costs more in engineering hours than the Transit Gateway data processing fees. If your team spends several hours a week debugging peering routes or updating Terraform modules for mesh peerings, the $0.05/hour attachment fee is a bargain.- VPC Peering: Best for performance and cost. Use for high-traffic databases or simple app clusters.
- Transit Gateway: Best for governance and scale. Use for 10+ VPCs or complex hybrid cloud setups.
- Hidden Cost: Remember the $0.02/GB processing fee on TGW. It adds up significantly at the petabyte scale.
- Hybrid approach: Many enterprises use TGW for general management but set up specific VPC Peerings for high-traffic service-to-service communication.
Frequently Asked Questions
Q. Is VPC peering cheaper than Transit Gateway?
A. Yes, VPC Peering is significantly cheaper. VPC Peering has no hourly charge and no data processing fee. You only pay for the underlying data transfer. Transit Gateway charges ~$0.05 per hour per attachment plus a $0.02 per GB data processing fee.
Q. Does Transit Gateway add latency?
A. Yes, but it is minimal. Transit Gateway typically adds about 100-200 microseconds (0.1ms to 0.2ms) of latency because it acts as an intermediate hop between VPCs. For most microservices, this is negligible, but for high-frequency trading or real-time gaming, it may matter.
Q. Can I use both VPC Peering and Transit Gateway together?
A. Absolutely. This is a common pattern called a "Hybrid Mesh." You use Transit Gateway for general connectivity and administration across the organization, but you create specific VPC Peering connections between high-traffic VPCs to bypass the TGW data processing fees.
Post a Comment