DEV Community

Francisco Escobar
Francisco Escobar

Posted on

AWS VPC Explained Like Building a City: The Ultimate Guide Every Developer Needs πŸ™οΈ

Feeling overwhelmed trying to understand AWS VPC? Do terms like subnets, gateways, and route tables sound like a foreign language?

I have great news: VPC is exactly like planning and building your own city. Once you grasp this analogy, you'll never be confused about cloud network architecture again.

πŸ—οΈ What is a VPC?

Imagine AWS gives you a blank piece of land and says: "Here, you can build your digital city".

Your VPC (Virtual Private Cloud) is that territory you define, where you have complete control over:

  • How you divide the space
  • Who can enter and leave
  • How different areas connect
  • What security level each zone has

Technically, you define a "CIDR block" - but think of it simply as the geographic coordinates of your city.

Example: Your city will have the base address 10.0.0.0/16, allowing you to create up to 65,536 different "lots".

🏘️ The Neighborhoods: Public vs Private Subnets

Public Neighborhoods (Public Subnets)

Like: Your city's downtown shopping district

  • Any visitor can arrive directly from the main highway (Internet)
  • Here you place: stores, restaurants, customer service offices
  • In AWS: Web servers, load balancers, public APIs

Private Neighborhoods (Private Subnets)

Like: Exclusive residential areas

  • Only residents and authorized people can enter
  • Contains: family homes, private warehouses, factories
  • In AWS: Databases, application servers, internal systems
πŸ™οΈ Your Digital City:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  CITY (VPC: 10.0.0.0/16)           β”‚
β”‚                                     β”‚
β”‚  πŸͺ PUBLIC NEIGHBORHOOD             β”‚
β”‚  └─ Web Store (10.0.1.0/24)        β”‚
β”‚  └─ API Gateway (10.0.2.0/24)      β”‚
β”‚                                     β”‚
β”‚  🏠 PRIVATE NEIGHBORHOOD            β”‚
β”‚  └─ Database (10.0.10.0/24)        β”‚
β”‚  └─ App Servers (10.0.11.0/24)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Enter fullscreen mode Exit fullscreen mode

πŸ›£οΈ The Street System: Route Tables

Route Tables are like your city's street system and signage:

  • They indicate how to get from one neighborhood to another
  • Define which routes are open or closed
  • Control whether you can leave the city to the Internet

Example signage:

🚏 "To go from Web District to DB District: Internal Street"
🚏 "To exit to Internet: Main Highway (IGW)"
🚏 "Private District: Exit only via Service Gate (NAT)"
Enter fullscreen mode Exit fullscreen mode

πŸšͺ The City Gates: Gateways

Internet Gateway (Main Entrance)

Like: Your city's main entrance

  • Allows visitors to enter directly from the Internet
  • Only public neighborhoods have direct access

NAT Gateway (Service Entrance)

Like: A special back door for residents

  • Private neighborhood folks can go out to "shop" (access Internet)
  • But outsiders can't enter through here
  • Example: Employees go to the grocery store, but strangers can't use that entrance

πŸ›‘οΈ Security: Two Levels of Protection

Security Groups (Personal Bodyguards)

Like: Having a security guard for each specific building

  • Control who can knock on YOUR door
  • Specific rules per resource
  • "Only my trusted friends can visit me"

Network ACLs (Neighborhood Checkpoints)

Like: Control posts at each neighborhood entrance

  • Check EVERYONE entering/leaving the entire neighborhood
  • General rules per subnet
  • "This neighborhood doesn't allow trucks after 10 PM"
πŸ”’ Layered Security:

Internet β†’ [Internet Gateway] β†’ [NACL] β†’ [Security Group] β†’ Your App
    ↑           ↑                  ↑            ↑
Highway     City Gate        Checkpoint    Personal Guard
Enter fullscreen mode Exit fullscreen mode

πŸŒ‰ Connecting Multiple Cities

VPC Peering (Direct Roads)

Scenario: Your company grows and you have multiple cities:

  • Development City (VPC Dev)
  • Production City (VPC Prod)
  • Testing City (VPC Test)

VPC Peering builds direct private roads between cities:

  • One-to-one connection, like an exclusive bridge
  • Private traffic, doesn't go through Internet
  • Limitation: With 5 cities you need 10 roads

Transit Gateway (Central Station)

Like: A central airport hub

  • All cities connect to the central station
  • From there you can reach any destination
  • Efficiency: 5 cities = only 5 connections to the hub
πŸš‰ Transit Gateway:

    City A ──┐
             β”‚
    City B ──┼── [Transit Gateway] 
             β”‚
    City C β”€β”€β”˜

One connection to rule them all!
Enter fullscreen mode Exit fullscreen mode

🏒 Real-World Use Cases

Startup Evolution

Phase 1: Small Town

VPC: "My First App"
β”œβ”€β”€ Public Subnet: Web + DB together
└── Everything simple, everything public
Enter fullscreen mode Exit fullscreen mode

Phase 2: Organized City

VPC: "My Growing App"
β”œβ”€β”€ Public Subnet: Frontend only
└── Private Subnet: Secure database
Enter fullscreen mode Exit fullscreen mode

Phase 3: Digital Empire

Development VPC:
β”œβ”€β”€ Public Subnet: Demos and testing
└── Private Subnet: Test databases

Production VPC:
β”œβ”€β”€ Public Subnet: Real app
└── Private Subnet: Production DB

Connected via Transit Gateway
Enter fullscreen mode Exit fullscreen mode

Enterprise E-commerce

πŸ™οΈ Main City (us-east-1):
β”œβ”€β”€ πŸͺ Web Zone: Online store
β”œβ”€β”€ βš™οΈ App Zone: Order processing
└── πŸ—„οΈ Data Zone: Main database

🌍 European City (eu-west-1):
β”œβ”€β”€ πŸͺ Web Zone: Localized store
β”œβ”€β”€ βš™οΈ App Zone: Regional processing
└── πŸ—„οΈ Data Zone: GDPR replica
Enter fullscreen mode Exit fullscreen mode

πŸš€ Practical Example: Netflix Simplified

Streaming City

  • Web District: What you see in your browser
  • Algorithm District: Personalized recommendations
  • Content District: Servers with movies

Analytics City

  • Data District: What each user watches
  • Profile District: Personal information
  • Billing District: Payment system

Connection: Transit Gateway allows sharing necessary data while maintaining separate security.

πŸ’‘ Benefits of Thinking Like an Urban Planner

1. Layered Security

Like having multiple security rings in your city:

  1. Border control (Internet Gateway)
  2. Neighborhood checkpoints (NACLs)
  3. Personal security (Security Groups)

2. Planned Scalability

  • Add neighborhoods without affecting existing ones
  • Build specialized cities
  • Connect as needed

3. Disaster Recovery

  • Main city + mirror city
  • If there's an "earthquake" in one region, the other continues

🎯 Design Principles

Start Simple

Village β†’ City β†’ Metropolis β†’ Global Empire
Enter fullscreen mode Exit fullscreen mode

Separate Responsibilities

Frontend β‰  Backend β‰  Database β‰  Analytics
Enter fullscreen mode Exit fullscreen mode

Security First

Public only what's necessary
Private everything sensitive
Minimum required connections
Enter fullscreen mode Exit fullscreen mode

πŸ”§ Essential Commands

# Create your first city
aws ec2 create-vpc --cidr-block 10.0.0.0/16

# Create public neighborhood
aws ec2 create-subnet --vpc-id vpc-xxx --cidr-block 10.0.1.0/24

# Create private neighborhood
aws ec2 create-subnet --vpc-id vpc-xxx --cidr-block 10.0.10.0/24

# Install main gate
aws ec2 create-internet-gateway
Enter fullscreen mode Exit fullscreen mode

πŸ—οΈ Step-by-Step: Building Your First Digital City

Step 1: Define Your Territory

# Your city boundaries
VPC CIDR: 10.0.0.0/16 (65,536 addresses)
Enter fullscreen mode Exit fullscreen mode

Step 2: Plan Your Neighborhoods

# Public district (facing Internet)
Public Subnet: 10.0.1.0/24 (256 addresses)

# Private district (internal only)
Private Subnet: 10.0.10.0/24 (256 addresses)
Enter fullscreen mode Exit fullscreen mode

Step 3: Build the Infrastructure

# Main entrance for visitors
Internet Gateway β†’ Public Subnet

# Service entrance for residents
NAT Gateway β†’ Private Subnet β†’ Internet Gateway
Enter fullscreen mode Exit fullscreen mode

Step 4: Set Up Security

# Neighborhood-level security
NACL: "No SSH from 0.0.0.0/0 to private subnet"

# Building-level security
Security Group: "Only port 443 from load balancer"
Enter fullscreen mode Exit fullscreen mode

🌟 Advanced Patterns

Multi-Tier Architecture

🌐 Internet
    ↓
πŸͺ Web Tier (Public Subnet)
    ↓
βš™οΈ App Tier (Private Subnet)
    ↓
πŸ—„οΈ Data Tier (Private Subnet)
Enter fullscreen mode Exit fullscreen mode

High Availability Setup

πŸ™οΈ City A (AZ-1a)     πŸ™οΈ City B (AZ-1b)
β”œβ”€β”€ Web District       β”œβ”€β”€ Web District
β”œβ”€β”€ App District       β”œβ”€β”€ App District
└── Data District      └── Data District
        ↕️                      ↕️
    [Load Balancer distributes traffic]
Enter fullscreen mode Exit fullscreen mode

Hybrid Cloud Connection

🏒 Your Office ←→ [VPN Gateway] ←→ πŸ™οΈ AWS City

Secure tunnel connecting your physical office 
to your digital city
Enter fullscreen mode Exit fullscreen mode

🚨 Common Pitfalls to Avoid

1. Everything Public

❌ Bad: Database in public subnet
βœ… Good: Database in private subnet with NAT access
Enter fullscreen mode Exit fullscreen mode

2. Overly Complex from Start

❌ Bad: 10 subnets for a simple app
βœ… Good: Start with 2 subnets, grow as needed
Enter fullscreen mode Exit fullscreen mode

3. Poor IP Planning

❌ Bad: /28 subnets (only 16 IPs each)
βœ… Good: /24 subnets (256 IPs each) for growth
Enter fullscreen mode Exit fullscreen mode

πŸ“Š Cost Optimization Tips

Smart Gateway Usage

πŸ’° NAT Gateway: $45/month + data transfer
πŸ’‘ Alternative: NAT Instance on small EC2

πŸ”„ Transit Gateway: $36/month + attachments
πŸ’‘ Alternative: VPC Peering for simple cases
Enter fullscreen mode Exit fullscreen mode

Right-Size Your Subnets

πŸ“ Plan for growth but don't over-provision
🎯 Use /24 for most use cases
πŸ” Monitor IP usage with VPC Flow Logs
Enter fullscreen mode Exit fullscreen mode

πŸŽ‰ Conclusion

AWS VPC stops being intimidating when you think of it as digital urban planning. Every component has a clear purpose, and the city analogy helps you make intuitive architectural decisions.

Remember:

  • VPC = Your territory/city
  • Subnets = Neighborhoods with different purposes
  • Gateways = Entry/exit doors
  • Security Groups = Personal bodyguards
  • NACLs = Neighborhood checkpoints
  • Route Tables = Street system

Next time you design an AWS architecture, ask yourself: "How would I organize this if it were a city?"

The beauty of this analogy is that it scales perfectly:

  • Startup = Small organized town
  • Growing Company = Expanding city with districts
  • Enterprise = Metropolitan area with connected cities
  • Global Corp = International network of cities

Did this analogy help you? πŸ’¬ Share in the comments how you'd plan your ideal "digital city".

Want more content like this? πŸ”” Follow me for more tutorials that make the cloud understandable for everyone.

Ready to build? πŸš€ Try designing your first VPC using this city planning approach!


#AWS #VPC #Cloud #DevOps #Architecture #Tutorial #Networking #Infrastructure

Top comments (1)

Collapse
 
wiangube profile image
William Antonio GuzmΓ‘n Bernal

A must-read for everyone at any level in AWS. Congratulations my friend!!!