Skip to main content

Command Palette

Search for a command to run...

Web Server vs Application Server - Explained with a Restaurant Analogy ๐Ÿฝ๏ธ

Published
โ€ข2 min read
M

Final Year Undergrad at IIIT Bhagalpur and a Full Stack Web Developer. Portfolio: https://www.heysohail.me/

In a production-ready web application, two key systems work together:
1. Web Server (Nginx)
2. Application Server (Uvicorn, using ASGI)

But what exactly do they do? Letโ€™s break it down ๐Ÿ‘‡

1๏ธโƒฃ ๐—ช๐—ฒ๐—ฏ ๐—ฆ๐—ฒ๐—ฟ๐˜ƒ๐—ฒ๐—ฟ (๐—ก๐—ด๐—ถ๐—ป๐˜…) - ๐—ง๐—ต๐—ฒ ๐—ฆ๐—บ๐—ฎ๐—ฟ๐˜ ๐—ช๐—ฎ๐—ถ๐˜๐—ฒ๐—ฟ
Nginx is like the well-trained waiter in a restaurant.

โ€ข Handles simple orders directly: If you just need a menu, napkin, or a glass of water (images, CSS, JavaScript), the waiter serves it instantly. No need to disturb the kitchen.
โ€ข Takes complex orders to the kitchen: When someone wants a freshly prepared dish (API call, page render, data processing), the waiter forwards the order to the kitchen calmly and efficiently.

Thatโ€™s where the application server comes in.

2๏ธโƒฃ ๐—”๐—ฝ๐—ฝ๐—น๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ฆ๐—ฒ๐—ฟ๐˜ƒ๐—ฒ๐—ฟ (๐—จ๐˜ƒ๐—ถ๐—ฐ๐—ผ๐—ฟ๐—ป ๐˜„๐—ถ๐˜๐—ต ๐—”๐—ฆ๐—š๐—œ) - ๐—ง๐—ต๐—ฒ ๐—ž๐—ถ๐˜๐—ฐ๐—ต๐—ฒ๐—ป ๐— ๐—ฎ๐—ป๐—ฎ๐—ด๐—ฒ๐—ฟ
Uvicorn (powered by ASGI: Asynchronous Server Gateway Interface) is like the modern kitchen manager.

โ€ข It receives the order from the waiter.
โ€ข Translates it into a language the chefs (your application code) understand.
โ€ข Assigns it to multiple line cooks (workers) who can work asynchronously.
โ€ข Handles multiple requests at the same time, without waiting for one to finish before starting another.

This is especially powerful for real-time applications, streaming, notifications, websockets, chat apps, etc.

๐—ช๐—ต๐˜† ๐—ฌ๐—ผ๐˜‚ ๐—–๐—ฎ๐—ปโ€™๐˜ ๐—ฆ๐—ฒ๐—ป๐—ฑ ๐—ฅ๐—ฒ๐—พ๐˜‚๐—ฒ๐˜€๐˜๐˜€ ๐——๐—ถ๐—ฟ๐—ฒ๐—ฐ๐˜๐—น๐˜† ๐˜๐—ผ ๐˜๐—ต๐—ฒ ๐—”๐—ฝ๐—ฝ๐—น๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป?
โ€ข The application logic is the recipe book and the skilled chefs.

โ€ข But it's not designed to handle thousands of raw, unfiltered requests from the internet. Doing so would be like letting thousands of hungry customers storm directly into your kitchen and shout their orders at the chef. It would be chaos.

โ€ข Thatโ€™s why we need Nginx and Uvicorn in between - to manage, route, filter, optimize, and scale the flow of orders.

More from this blog