Ace Cloud Interviews
Home/AWS Tutorial/Transit Gateway
🌐

AWS Networking & CDN

Transit Gateway

Central network hub connecting thousands of VPCs and on-premises networks

AWS Transit Gateway acts as a regional network hub that connects VPCs and on-premises networks through a central point, eliminating the need for complex VPC peering meshes. It supports thousands of attachments, enables transitive routing, and provides centralized control over inter-VPC and hybrid network traffic flows.

Transit Gateway Architecture and Components

Transit Gateway (TGW) replaces a web of VPC peering connections with a hub-and-spoke model. Each spoke attaches to the TGW, and routing tables on the TGW control which spokes can communicate.

ComponentDescriptionKey Limit
TGWRegional virtual router; one per region per account (shareable via RAM)Up to 5,000 attachments
AttachmentConnects a VPC, VPN, DX, or TGW peer to the hubOne subnet per AZ per VPC attachment (recommend all AZs)
TGW Route TableControls which attachments can route to which targetsMultiple route tables enable segmentation
Route PropagationAttachments can propagate their CIDRs to TGW route tablesAutomatic vs static routes
AssociationLinks an attachment to a specific TGW route tableEach attachment associated with exactly one route table
PeeringConnect TGWs across regions or accountsStatic routes only; no route propagation across peers
💡

Always attach a subnet in every AZ you use for each VPC. If you only attach us-east-1a, traffic from resources in us-east-1b must cross AZs to reach the TGW attachment, incurring data transfer charges and adding latency.

Routing and Network Segmentation

TGW's multiple route tables enable network segmentation without complex firewall rules. Common patterns include separating production from development and inspecting traffic centrally.

PatternRoute Table DesignUse Case
Full mesh (simple)One route table, all attachments associate and propagateSmall environments; all VPCs can talk to each other
Segmented (prod vs dev)Separate route tables per tier; no cross-propagationPrevent dev VPCs from reaching prod; compliance isolation
Centralized inspectionAll VPCs default route to security VPC with firewallInline inspection via Network Firewall or third-party NVA
Shared servicesShared services VPC propagates to all; others propagate to shared onlyDNS, AD, monitoring VPCs accessible by all

For centralized egress inspection, route VPC default routes (0.0.0.0/0) through the TGW to a centralized security VPC that contains a Network Firewall or NAT Gateway. This reduces NAT Gateway costs (one instead of one per VPC) and provides a single inspection point.

bash
# Create a Transit Gateway
aws ec2 create-transit-gateway \
  --description "Central hub" \
  --options AmazonSideAsn=64512,AutoAcceptSharedAttachments=disable,DefaultRouteTableAssociation=disable,DefaultRouteTablePropagation=disable

# Attach a VPC to Transit Gateway
aws ec2 create-transit-gateway-vpc-attachment \
  --transit-gateway-id tgw-xxxx \
  --vpc-id vpc-xxxx \
  --subnet-ids subnet-aaa subnet-bbb

Transit Gateway vs VPC Peering

AspectVPC PeeringTransit Gateway
Transitive routingNoYes
Number of connectionsN*(N-1)/2 for full meshN connections to one TGW
Management complexityIncreases quadratically with VPC countLinear; centrally managed
BandwidthNo limit (uses AWS backbone)50 Gbps per VPC attachment
CostData transfer only ($0.01/GB cross-AZ)Attachment ($0.05/hr) + data ($0.02/GB)
Cross-account/regionYes (both)Yes (peering for cross-region)
Routing controlRoute table per VPC onlyCentralized TGW route tables
Best for2-3 VPCs; simple connectivity4+ VPCs; complex routing; hybrid networks
💡

For fewer than 3-4 VPCs with simple connectivity needs, VPC Peering is cheaper and simpler. TGW overhead ($36/month per attachment) only pays off when you have many VPCs or need centralized routing control.

Multicast, Inter-Region Peering, and Pricing

TGW supports multicast traffic delivery and inter-region TGW peering for global architectures.

ComponentCostNotes
VPC attachment$0.05/hr (~$36/month)Per attachment regardless of traffic
VPN attachment$0.05/hrPer VPN connection
Direct Connect attachment$0.05/hrVia Transit VIF
Data processing$0.02/GBAll traffic through TGW
Peering attachment$0.05/hr per attachmentCross-region data transfer also charged
MulticastAdditional per-hour + per-GB ratesOpt-in feature
⚠️

TGW data processing charges apply to ALL traffic - including VPC-to-VPC traffic that would be free with VPC Peering. For high-bandwidth workloads (e.g., big data pipelines between VPCs), calculate whether TGW data costs outweigh peering complexity.

🎯

Interview Focus Points

  • 1When would you use Transit Gateway instead of VPC Peering? What is the break-even point?
  • 2Explain how TGW route tables enable network segmentation between production and development.
  • 3How would you design centralized egress with inspection using Transit Gateway and Network Firewall?
  • 4What is the difference between route table association and route propagation in Transit Gateway?
  • 5How does TGW handle cross-region connectivity? What are the limitations?
  • 6Explain how you would migrate from a VPC Peering mesh to Transit Gateway with zero downtime.
  • 7What happens to traffic routing when a TGW attachment subnet is in only one AZ?
  • 8How does Transit Gateway connect to on-premises via Direct Connect?