Differences between web-garden and a web-farm in Javascript

In web application deployment, understanding the difference between Web Garden and Web Farm architectures is crucial for scaling JavaScript applications effectively. Both approaches handle increased traffic differently through process-based and server-based scaling respectively.

What is a Web Garden?

A Web Garden is a web hosting system that comprises multiple "processes" running on a single server. This means we have one physical machine executing multiple worker processes to handle incoming requests concurrently.

Single Server (Web Garden) Process 1 Process 2 Process 3 Shared Resources (CPU, Memory, Disk)

What is a Web Farm?

A Web Farm is a web hosting system that comprises multiple "servers" or computers working together. Unlike a web garden that runs on a single server, a web farm distributes the application across multiple physical machines, providing true horizontal scaling.

Load Balancer Server 1 Node.js App Server 2 Node.js App Server 3 Node.js App Web Farm Architecture

JavaScript Application Examples

Web Garden: Node.js Cluster Module

const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;

if (cluster.isMaster) {
  console.log(`Master ${process.pid} is running`);
  
  // Fork workers (multiple processes on same server)
  for (let i = 0; i < numCPUs; i++) {
    cluster.fork();
  }
} else {
  // Worker process
  http.createServer((req, res) => {
    res.writeHead(200);
    res.end(`Hello from worker ${process.pid}<br>`);
  }).listen(8000);
  
  console.log(`Worker ${process.pid} started`);
}

Web Farm: Multiple Server Setup

// Server 1 - app.js
const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.json({ 
    message: 'Hello from Server 1', 
    server: 'web-server-1',
    pid: process.pid 
  });
});

app.listen(3001, () => {
  console.log('Server 1 running on port 3001');
});

// Server 2 would be identical but on port 3002
// Load balancer (nginx/HAProxy) distributes traffic

Key Differences

Aspect Web Garden Web Farm
Hardware Single server/machine Multiple servers/machines
Scalability Type Vertical (logical) Horizontal (physical)
Resource Sharing Shared CPU, memory, disk Dedicated resources per server
Fault Tolerance Single point of failure High availability
Cost Lower (one machine) Higher (multiple machines)
Session Management Easier (same memory space) Complex (requires sticky sessions or shared storage)

When to Use Each Approach

Web Garden is ideal for:

  • CPU-intensive JavaScript applications
  • Budget-constrained deployments
  • Applications with shared state requirements

Web Farm is better for:

  • High-traffic Node.js applications
  • Mission-critical systems requiring redundancy
  • Applications needing true horizontal scaling

Conclusion

Web Garden provides logical scalability through multiple processes on one server, while Web Farm offers physical scalability across multiple machines. Choose Web Garden for cost-effective scaling and Web Farm for high availability and true horizontal growth.

Updated on: 2026-03-15T23:18:59+05:30

462 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements