CodeHive
open main menu
Scaling Strategies
Part of series: MongoDB Roadmap

Scale Up vs Scale Out: The Eternal Debate

/ 2 min read

Welcome to Day 3! βš–οΈ

Your app is slow. You need more power. You have two choices.

1. Vertical Scaling (Scale Up) πŸ—Ό

Definition: Buying a bigger machine. Moving from an 8GB RAM server to a 64GB RAM server.

Pros:

  • βœ… Simplicity: No code changes. No sharding complexity.
  • βœ… Consistency: Running on one node (primary) is easier to reason about.

Cons:

  • ❌ Ceiling: There is a limit. You can’t buy a 100 Petabyte RAM server.
  • ❌ Downtime: You usually have to stop the server to upgrade it.
  • ❌ Cost: Massive servers are exponentially more expensive than commodity hardware.

2. Horizontal Scaling (Scale Out) πŸ™οΈ

Definition: Adding more machines. Moving from 1 server to 10 smaller servers (Sharidng).

Pros:

  • βœ… Infinite Scale: Need more space? Just add another node.
  • βœ… No Downtime: Add nodes while the cluster runs.
  • βœ… Cost: Commodity hardware is cheap.

Cons:

  • ❌ Complexity: Sharding keys, balancing, routing.
  • ❌ Network Overhead: Queries might need to check multiple shards.

3. When to Switch?

Start with Vertical Scaling. It is perfectly fine to run a Replica Set on a big 64GB/128GB RAM instance. It handles 95% of use cases.

Switch to Sharding (Horizontal) when:

  1. Dataset > 2TB: Restoring backups takes too long.
  2. RAM limit hit: Your working set (indexes + hot data) exceeds available RAM.
  3. Writes per second spike: A single Primary can’t handle the write load (e.g., IoT data).

🧠 Daily Challenge

Check your current server stats.

  • db.stats().dataSize
  • db.serverStatus().mem Are you close to the limit? Calculated guess: If your data doubles every month, when will you need to shard?

See you on Day 4 for Monitoring & Optimization Tools! πŸ› οΈ


Next Step

Next: Monitoring Optimization β†’