Cloud Computing →
Cloud Basics
What is Cloud Computing?
Cloud computing is the on-demand delivery of computing resources like servers, storage, databases, networking, and software over the internet with pay-as-you-go pricing.
Why Cloud?
- No upfront infrastructure cost
- Scale when traffic spikes
- High availability by default
- Faster deployment
Key Concept:
You rent computing power instead of buying and maintaining physical servers.
What are the service models: IaaS, PaaS, SaaS?
Cloud services are offered at three levels of abstraction:
IaaS (Infrastructure as a Service)
- You rent virtual machines, storage, networks
- You manage: OS, runtime, applications
- Examples: AWS EC2, Azure VMs, Google Compute Engine
PaaS (Platform as a Service)
- You deploy applications
- Platform manages: OS, runtime, scaling
- Examples: AWS Elastic Beanstalk, Google App Engine, Heroku
SaaS (Software as a Service)
- You use complete applications
- Everything is managed for you
- Examples: Gmail, Salesforce, Office 365, Dropbox
Rule of thumb: IaaS = most control, SaaS = least control. More control = more responsibility.
Cloud vs On-Premise
| On-Premise | Cloud |
|---|---|
| High CAPEX | Low CAPEX |
| Manual scaling | Auto scaling |
| Maintenance headache | Managed services |
| Limited availability | Multi-region HA |
| Slow provisioning | Instant provisioning |
When to use on-premise:
- Strict regulatory requirements
- Legacy systems that can't migrate
- Extremely predictable workloads
Cloud Deployment Models: Public, Private, Hybrid, Multi-Cloud
Public Cloud
- Shared infrastructure
- Cost-effective
- Scalable
- Examples: AWS, Azure, GCP
Private Cloud
- Dedicated resources
- More control
- Higher cost
- Examples: VMware, OpenStack
Hybrid Cloud
- On-prem + public cloud
- Common in enterprises
- Flexibility in data placement
Multi-Cloud
- Multiple cloud providers
- Avoid vendor lock-in
- Complex networking and monitoring
Advantages and Disadvantages of Cloud
Advantages:
- Cost efficiency – Pay only for what you use
- Scalability – Handle traffic spikes automatically
- Global reach – Deploy in multiple regions
- Speed – Provision resources in minutes
- Reliability – Built-in redundancy and backups
- Security – Enterprise-grade security by default
Disadvantages:
- Vendor lock-in – Hard to switch providers
- Downtime – You depend on cloud provider's uptime
- Limited control – Less control than on-premise
- Compliance – May not meet all regulatory requirements
- Cost unpredictability – Bills can spike if not monitored
What is Virtualization?
Virtualization means running multiple virtual machines on one physical machine using a hypervisor.
Hypervisor Types:
Type 1 (Bare Metal)
- Runs directly on hardware
- Used in production
- Examples: VMware ESXi, Hyper-V, KVM
Type 2 (Hosted)
- Runs on host OS
- Used for testing
- Examples: VirtualBox, VMware Workstation
Why virtualization matters:
- Better hardware utilization
- Isolation
- Scalability
Virtualization is the foundation of cloud computing. Without it, cloud wouldn't exist.
Containers vs Virtual Machines
Virtual Machines
- Each VM has its own OS
- Heavy
- Slower boot time
- More isolation
Containers
- Share host OS kernel
- Lightweight
- Faster startup
- Better resource utilization
Interview line:
👉 Containers solve deployment consistency, not security by default.
When to use what:
- VMs: Need different OS, strong isolation, legacy apps
- Containers: Microservices, fast deployment, resource efficiency
Scalability vs Elasticity (Asked Constantly)
Scalability
Ability to increase capacity.
- Vertical: Bigger machine (scale up)
- Horizontal: More machines (scale out) – preferred
Elasticity
Ability to automatically scale based on real-time demand.
- Responds to traffic changes
- Scales up when needed, scales down when idle
- Cost optimization
Key Difference:
Scalability = capacity. Elasticity = automatic + dynamic.
High Availability vs Fault Tolerance
High Availability
- System minimizes downtime
- Uses redundancy
- Example: Multiple instances behind a load balancer
- 99.9% uptime
Fault Tolerance
- System continues working even when components fail
- More expensive
- Used in mission-critical systems
- Example: Active-active replication across regions
| High Availability | Fault Tolerance |
|---|---|
| Minimizes downtime | Zero downtime |
| Acceptable brief outages | No outages |
| Cost-effective | Expensive |
Compute Services
What is a Virtual Machine? (EC2-like concepts)
What is a Virtual Machine?
A Virtual Machine (VM) is a software-based computer running on shared physical hardware using virtualization. Each VM has:
- Its own OS
- Allocated CPU, RAM, storage
- Network interface
Think of it as renting an apartment in a huge building. You don't own the building, but you control everything inside your flat.
Core VM Concepts Interviewers Expect
Instance Types
VMs come in predefined configurations optimized for different workloads:
- Compute optimized – CPU-heavy tasks
- Memory optimized – In-memory apps, caching
- Storage optimized – Databases, analytics
- General purpose – Balanced workloads
AMI / Image
A machine image contains:
- OS
- Pre-installed software
- Configuration
Launching a VM = booting from an image.
VM Lifecycle
- Launch
- Running
- Stopped
- Terminated
Stopped ≠ terminated. Stopped keeps disk, terminated deletes everything. Many people learn this the hard way.
When to Use Virtual Machines
- Legacy applications
- Long-running services
- Need full OS control
- Custom networking or security requirements
VM Pros & Cons
Pros:
- Full control
- Predictable performance
- Mature and stable
Cons:
- Manual scaling
- Idle cost when unused
- Slower startup compared to containers/serverless
What is Auto Scaling?
What is Auto Scaling?
Auto Scaling automatically increases or decreases the number of VM instances based on demand.
Purpose:
- Handle traffic spikes
- Maintain performance
- Reduce cost
How Auto Scaling Works
Auto Scaling is based on metrics + policies.
Common Scaling Metrics
- CPU utilization
- Memory usage
- Request count
- Network traffic
Scaling Types
Scale Out (Horizontal Scaling)
- Add more instances
- Preferred in cloud environments
Scale In
- Remove unused instances
- Saves cost
Scaling Policies
Target Tracking
"Keep CPU at 60%."
Cloud handles the math.
Step Scaling
Scale in steps based on thresholds.
Scheduled Scaling
Scale at fixed times (predictable traffic).
Benefits:
- Cost optimization
- Performance stability
- Handles unpredictable loads
Load Balancers (L4 vs L7)
What is a Load Balancer?
A load balancer distributes incoming traffic across multiple backend instances to:
- Prevent overload
- Improve availability
- Enable scaling
Layer 4 Load Balancer (Transport Layer)
Works At:
- TCP / UDP level
Characteristics:
- Routes traffic based on IP + port
- Fast
- Less intelligent
Use Cases:
- Low latency systems
- Real-time applications
- Simple traffic forwarding
Layer 7 Load Balancer (Application Layer)
Works At:
- HTTP / HTTPS level
Characteristics:
- Content-based routing
- URL-based routing
- Header-based routing
- SSL termination
Use Cases:
- Web applications
- Microservices
- Path-based routing (/api → API servers, /static → CDN)
L4 vs L7 Comparison
| Feature | L4 | L7 |
|---|---|---|
| Speed | Faster | Slightly slower |
| Intelligence | Low | High |
| Routing | IP + Port | URL, headers, content |
| SSL Termination | ✗ | ✓ |
Interview Tip:
Use L7 for HTTP/HTTPS applications. Use L4 for non-HTTP or low-latency requirements.
Serverless Computing (Lambda-Style)
What is Serverless?
Serverless means:
- You don't manage servers
- Code runs in response to events
- Billing is per execution time
Servers still exist. You just don't babysit them.
Key Characteristics
- Event-driven
- Stateless
- Auto-scaled by cloud provider
- Short-lived execution
Common Triggers:
- HTTP requests
- File uploads
- Database changes
- Scheduled jobs
Serverless Execution Flow
- Event occurs
- Function is invoked
- Code runs
- Function shuts down
No idle cost. Finally, something efficient.
When to Use Serverless
- APIs
- Background jobs
- Event processing
- Spiky or unpredictable traffic
Cold Start Problem
A cold start is the delay when a function is invoked after inactivity.
Why it happens:
- Function needs to be initialized
- Runtime environment needs to spin up
Solutions:
- Provisioned concurrency (keep functions warm)
- Use lightweight runtimes
- Optimize initialization code
Pros:
- No server management
- Automatic scaling
- Pay per execution
- Fast deployment
Cons:
- Cold start latency
- Execution time limits
- Vendor lock-in
- Debugging complexity
Interview Insight:
Serverless is not always cheaper. For constant traffic, VMs can be more cost-effective.
Storage Services
Content coming soon...