No history yet

VPC Network Design

Architecting Your Virtual Network

A Virtual Private Cloud (VPC) is the network foundation of your AWS environment. Think of it as the blueprint for a custom-built data centre, but entirely virtual. The first decision is picking an IP address range. For this, we use private IP address spaces defined by RFC 1918, which are reserved for internal networks and aren't routable on the public internet. Common choices are ranges like 10.0.0.0/8, 172.16.0.0/12, or 192.168.0.0/16.

Let's choose a 10.0.0.0/16 block for our VPC. This gives us 65,536 private IP addresses to work with. This large block provides ample room for growth and segmentation without needing to re-architect our network later. It's like buying a large plot of land before building a house; you have the space to add a garden, a garage, and a guest house as your needs evolve.

Subnets and Availability

A VPC on its own is just an empty space. To make it useful, we carve it up into smaller networks called subnets. Each subnet lives entirely within a single Availability Zone (AZ), which is a distinct data centre within an AWS Region. To build a resilient, highly available architecture, we create parallel subnets across multiple AZs. If one data centre has an issue, your application can continue running in another.

We typically create at least three types of subnets in each AZ:

  • Public Subnets: For resources that need direct internet access, like web servers or Application Load Balancers.
  • Private Subnets: For backend application servers that should not be directly exposed to the internet.
  • Data Subnets: An even more restricted layer for databases, ensuring they are isolated from all but the application servers that need to connect to them.

When you create a subnet, not all IP addresses are available for you to use. AWS reserves the first four and the last IP address in every subnet CIDR block for its own networking purposes. This is often called the 'AWS 5-IP Reserved Rule'.

For a subnet with the CIDR block 10.0.1.0/24, the reserved addresses are 10.0.1.0, 10.0.1.1, 10.0.1.2, 10.0.1.3, and 10.0.1.255. This means out of 256 possible addresses, only 251 are available for your resources.

Subnet PurposeAvailability Zone AAvailability Zone BUsable IPs
Public10.0.1.0/2410.0.2.0/24251 each
Private (App)10.0.10.0/2410.0.20.0/24251 each
Private (Data)10.0.100.0/2410.0.200.0/24251 each

Routing Traffic In and Out

Creating subnets provides isolation, but now we need to define how they communicate with each other and the outside world. This is handled by Route Tables. A route table contains a set of rules, called routes, that determine where network traffic from your subnet is directed.

What makes a subnet 'public' or 'private' is not an inherent property, but rather the routes in the route table associated with it.

  • Public Subnets: To make a subnet public, we create an Internet Gateway (IGW) and attach it to our VPC. Then, we add a route to the subnet's route table that directs all outbound internet-bound traffic (0.0.0.0/0) to the IGW. This allows resources like web servers to receive traffic from the internet and respond.

  • Private Subnets: Resources in private subnets, like application or database servers, don't have a direct route to the internet. To allow them to initiate outbound connections—for example, to download software updates or call external APIs—we use a NAT (Network Address Translation) device. The private subnet's route table will point its 0.0.0.0/0 traffic to this NAT device, which resides in a public subnet.

For translating private IP addresses to public ones, you have two main options: a NAT Gateway or a NAT Instance.

FeatureNAT GatewayNAT Instance
ManagementAWS ManagedSelf-Managed (on an EC2 instance)
AvailabilityHighly available within an AZMust be managed for high availability
BandwidthBursts up to 45 GbpsDepends on EC2 instance type
CostPriced per hour + data processedPriced per EC2 instance hour
MaintenanceNone (handled by AWS)User responsible for patching/updates

A NAT Gateway is the modern, managed solution. It offers higher bandwidth, better availability, and requires no administration. A NAT Instance is essentially just a regular EC2 instance configured to perform NAT. It's cheaper for low-traffic workloads but requires you to manage its availability, security patching, and instance sizing.

For most production applications, a NAT Gateway is the preferred choice. The operational overhead and availability risks of a NAT Instance often outweigh the cost savings.

Shielding Your Backend

Directly exposing application servers to the internet is a security risk. Instead, we place them in private subnets and use an Application Load Balancer (ALB) in the public subnet to securely distribute incoming traffic.

The ALB has a public IP address and listens for user requests. When a request arrives, the ALB forwards it to a healthy application server in a private subnet. The servers themselves only need private IP addresses. This design shields your application fleet from direct internet exposure.

The route table for the public subnet directs internet traffic to the ALB, and the ALB uses the VPC's internal network to communicate with the application servers. The application servers, in turn, use the route to the NAT Gateway for any outbound connections they need to make. This creates a clean, secure, and one-way flow of traffic.

Lesson image

By thoughtfully planning your CIDR blocks, segmenting your network into public and private subnets across multiple AZs, and using the correct gateways and route tables, you create a VPC architecture that is secure, scalable, and highly available. This structured approach is fundamental to building robust applications on AWS.

Quiz Questions 1/6

What is a Virtual Private Cloud (VPC) most analogous to in a traditional IT environment?

Quiz Questions 2/6

What primarily determines whether a subnet is considered 'public' or 'private'?