Ace Cloud Interviews
🌐

AWS Networking & CDN

VPC

Logically isolated virtual network with full control over IP ranges, subnets, and routing tables

Amazon VPC (Virtual Private Cloud) gives you a logically isolated section of the AWS cloud where you can launch resources in a virtual network you define. You have full control over IP address ranges, subnets, route tables, and network gateways - making VPC the foundational networking layer for nearly every AWS architecture.

VPC Architecture and Core Components

A VPC spans all Availability Zones in a region. You carve it into subnets, each pinned to a single AZ. Public subnets route to an Internet Gateway; private subnets route outbound traffic through a NAT Gateway or stay fully isolated.

ComponentPurposeKey Detail
VPC CIDRIP address space for the VPCRange /16 to /28; cannot be changed after creation
SubnetAZ-scoped IP range within the VPCFirst 4 and last 1 IP reserved by AWS
Internet Gateway (IGW)Horizontally scaled gateway to the internet1 per VPC; attach to VPC, add route 0.0.0.0/0 -> IGW
NAT GatewayOutbound internet for private subnetsDeployed in public subnet; costs per hour + data processed
Route TableControls traffic routing per subnetEach subnet associated with exactly one route table
Security GroupStateful instance-level firewallAllow rules only; return traffic automatically allowed
Network ACLStateless subnet-level firewallAllow and deny rules; rules evaluated in order by number
VPC EndpointPrivate path to AWS servicesGateway (S3/DynamoDB) or Interface (most services)
💡

Default VPCs come pre-configured with a /16 CIDR, one public subnet per AZ, an IGW, and a route table. They are fine for experiments but most production workloads use custom VPCs with private subnets.

Subnet Design and Routing Patterns

A three-tier subnet layout is the standard starting point: public (load balancers), private app (EC2/ECS), and private data (RDS/ElastiCache). Spread each tier across at least two AZs for high availability.

TierRoute Table HasTypical Resources
Public0.0.0.0/0 -> IGWALB, NAT Gateway, Bastion hosts
Private App0.0.0.0/0 -> NAT GatewayEC2, ECS tasks, Lambda in VPC
Private DataLocal routes onlyRDS, ElastiCache, OpenSearch

NAT Gateway must live in a public subnet and have an Elastic IP. Create one per AZ to avoid cross-AZ data transfer charges and single points of failure.

bash
# Create a VPC
aws ec2 create-vpc --cidr-block 10.0.0.0/16 --tag-specifications 'ResourceType=vpc,Tags=[{Key=Name,Value=prod-vpc}]'

# Create public subnet in us-east-1a
aws ec2 create-subnet --vpc-id vpc-xxxx --cidr-block 10.0.1.0/24 --availability-zone us-east-1a

# Create and attach Internet Gateway
aws ec2 create-internet-gateway
aws ec2 attach-internet-gateway --vpc-id vpc-xxxx --internet-gateway-id igw-xxxx

# Add route in public route table
aws ec2 create-route --route-table-id rtb-xxxx --destination-cidr-block 0.0.0.0/0 --gateway-id igw-xxxx
⚠️

Enabling "Auto-assign public IPv4" on a subnet does not make it a public subnet. A subnet is public only when its route table has a route to an IGW. Forgetting the route table update is a common interview gotcha.

Security Groups vs Network ACLs

Security Groups and NACLs both filter traffic but operate at different layers and have different statefulness models.

FeatureSecurity GroupNetwork ACL
LevelInstance / ENISubnet
StatefulnessStateful - return traffic automatically allowedStateless - must explicitly allow inbound and outbound
Rule typesAllow onlyAllow and Deny
Rule evaluationAll rules evaluated togetherRules evaluated in ascending number order; first match wins
DefaultDeny all inbound, allow all outboundAllow all inbound and outbound (default NACL)
AssociationMany instances, many SGsOne NACL per subnet; one subnet per NACL
💡

Use Security Groups as your primary control - they are easier to manage and stateful. Use NACLs as a second layer to block specific IPs at scale (e.g., blocking a /24 range from a known bad actor without adding rules to every SG).

VPC Connectivity Options

As architectures grow you need to connect VPCs to each other and to on-premises networks. Each option has different trade-offs in complexity, cost, and scalability.

OptionUse CaseTransitive?Bandwidth Limit
VPC PeeringConnect two VPCs (same or cross-account)NoNo limit (uses AWS backbone)
Transit GatewayHub-and-spoke for many VPCsYes50 Gbps per VPC attachment
PrivateLinkExpose a service to consumers privatelyN/APer-endpoint limits
Site-to-Site VPNConnect on-premises to VPCNo (with TGW: yes)1.25 Gbps per tunnel
Direct ConnectDedicated physical link to AWSWith DXGW: yes1-100 Gbps
⚠️

VPC Peering is not transitive. If VPC-A peers with VPC-B and VPC-B peers with VPC-C, traffic cannot flow A -> B -> C without a direct peering between A and C. This is a very common exam and interview question.

VPC Pricing and Cost Optimization

The VPC itself is free. Costs come from attached resources and data transfer.

ResourceCost DriverOptimization
NAT Gateway$0.045/hr + $0.045/GB processedShare one NAT GW per AZ; use VPC Endpoints for S3/DynamoDB to bypass NAT
VPC Endpoints (Interface)$0.01/hr per AZ + $0.01/GBWorth it if NAT Gateway data costs exceed endpoint hourly cost
VPC PeeringData transfer between AZs/regionsKeep traffic within same AZ where possible; use TGW for many-to-many
Elastic IP$0.005/hr when not in useRelease unused EIPs immediately
Transit Gateway$0.05/hr per attachment + $0.02/GBUse for 3+ VPCs; peering is cheaper for just two
💡

S3 and DynamoDB Gateway Endpoints are free and eliminate NAT Gateway data charges for those services. Always enable them in every VPC - there is no reason not to.

🎯

Interview Focus Points

  • 1What is the difference between a Security Group and a Network ACL? When would you use each?
  • 2Explain why VPC Peering is not transitive and how Transit Gateway solves that problem.
  • 3A private subnet instance cannot reach the internet. Walk through your troubleshooting steps.
  • 4How would you design a multi-account VPC architecture for a large enterprise?
  • 5What is the difference between an Interface VPC Endpoint and a Gateway VPC Endpoint?
  • 6How do you reduce NAT Gateway costs in a large VPC setup?
  • 7Can two VPCs with overlapping CIDR blocks be peered? What would you do instead?
  • 8Explain the reserved IP addresses in a subnet and why they matter for capacity planning.
  • 9How does VPC Flow Logs work and what are its limitations for security monitoring?