What is VPC peering?

·

2 min read

What is VPC peering?

In a microservices architecture, such as one used by an e-commerce platform like Amazon, services like shopping cart, payments, and order tracking need to communicate securely and efficiently across different virtual private clouds (VPCs). Understanding how to interconnect these VPCs while adhering to AWS limitations and best practices is crucial. Here’s how to achieve this using VPC peering while addressing its non-transitive nature.

VPC Peering Overview

VPC peering allows two VPCs to communicate privately using AWS's network, as if they are within the same network. Key considerations include:

  1. No Overlapping CIDR Blocks: The VPCs must have distinct IP address ranges.

  2. Non-Transitive Peering: If VPC A is peered with VPC B, and VPC B is peered with VPC C, VPC A cannot communicate directly with VPC C.

  3. Route Tables: You must update the route tables in each VPC to enable communication between peered VPCs.

Scenario Breakdown

  1. Peering VPC-1 and VPC-2:

    • VPC-1: Hosts the Shopping Cart service.

    • VPC-2: Hosts the Payments service.

    • Purpose: Allow data exchange when a customer adds a product to the cart and proceeds to payment.

  2. Peering VPC-2 and VPC-3:

    • VPC-3: Hosts the Order Tracking service.

    • Purpose: Allow the Payments service to send order details to the Order Tracking service.

  3. Peering VPC-1 and VPC-3:

    • Purpose: Allow the Shopping Cart service to communicate with the Order Tracking service for tracking orders and leaving reviews.

Non-Transitive Peering Explanation

  • Non-Transitive Nature: If VPC-1 is peered with VPC-2, and VPC-2 is peered with VPC-3, VPC-1 and VPC-3 cannot communicate directly through VPC-2. Each VPC must establish its own peering connections.

    Example:

    • VPC-1 and VPC-2 are peered: Shopping Cart service can communicate with the Payments service.

    • VPC-2 and VPC-3 are peered: Payments service can communicate with the Order Tracking service.

    • VPC-1 and VPC-3 must also be peered: For direct communication between Shopping Cart and Order Tracking services.

Conclusion

To ensure seamless communication between microservices hosted on different VPCs, establish individual VPC peering connections between each pair of VPCs. This approach adheres to the non-transitive nature of VPC peering, ensuring secure and efficient communication pathways. Updating route tables appropriately maintains efficient data flow across your microservices architecture, supporting the needs of a globally used application like an e-commerce platform.