
3. What is a Backend, how do they work and why do we need them?
Sriniously
Overview
This video explains the fundamental concept of a backend in web development. It details how a backend server functions, from receiving requests via domain names and IP addresses, through firewalls, to reverse proxies like Nginx, and finally to the application server. The video emphasizes the crucial role of backends in managing data, handling complex logic, and ensuring security, contrasting their capabilities with the limitations of frontends. It highlights why backends are essential for tasks like data persistence, real-time notifications, and efficient database interactions, which cannot be reliably or securely performed on the client-side.
Save this permanently with flashcards, quizzes, and AI chat
Chapters
- A backend is a computer that listens for incoming requests (HTTP, WebSocket, gRPC) on open ports accessible over the internet.
- It serves content (static files, JSON) and accepts data from clients or frontends.
- It's called a 'server' because it 'serves' resources and functionality.
- Backends are essential for processing requests and managing data that frontends cannot handle.
- A request starts with a domain name, which is resolved by a DNS server to an IP address.
- The IP address typically points to a cloud instance (e.g., AWS EC2) where the backend is hosted.
- Before reaching the instance, requests pass through firewalls (e.g., AWS Security Groups) that must allow specific ports (like 80 for HTTP, 443 for HTTPS).
- A reverse proxy (like Nginx) often sits in front of the application server, managing traffic, SSL certificates, and routing requests to the correct application port (e.g., 3001 for a Node.js app).
- Backends are needed to manage and persist data, such as user information, actions, and application state.
- They handle complex logic and interactions that occur between user actions and system responses (e.g., liking a post and triggering a notification).
- A centralized backend holds all necessary information about all users and the system's state, unlike personalized frontends.
- The core responsibility of a backend revolves around fetching, receiving, and persisting data, and performing actions related to that data.
- Frontends (like Next.js apps) are fetched by the browser as HTML, CSS, and JavaScript files.
- The browser then executes this code on the client's machine, rendering the UI and handling user interactions.
- Unlike backends where processing happens on the server, frontends delegate execution to the client's browser.
- Browsers are sandboxed environments, limiting access to the operating system, file system, and external resources due to security policies like CORS.
- Security: Browsers restrict access to sensitive resources like file systems and environment variables, making them unsuitable for backend operations.
- API Access: Frontend JavaScript faces Cross-Origin Resource Sharing (CORS) restrictions, limiting its ability to call arbitrary external APIs without specific server configurations.
- Database Interaction: Browsers lack native drivers and efficient connection management (like connection pooling) required for direct, high-volume database communication.
- Computing Power: Client devices have variable and often limited processing power, making them unreliable for heavy business logic that needs consistent performance.
Key takeaways
- Backends are the computational engines behind web applications, responsible for data management and complex processing.
- The journey of a web request involves multiple layers: DNS, IP addressing, firewalls, and reverse proxies before reaching the application.
- Centralized data storage and management on the backend are essential for application consistency and user experience.
- Frontends execute code in the client's browser, while backends execute code on a server.
- Browser security sandboxing and restrictions (like CORS) prevent frontends from performing many critical backend tasks.
- Efficient database interaction, secure access to resources, and scalable computing power necessitate dedicated backend servers.
Key terms
Test your understanding
- What is the primary function of a backend server in a web application?
- Describe the sequence of events and infrastructure components involved when a user's browser sends a request to a backend server.
- Why is it not feasible or secure to perform all application logic, such as database interactions, directly from the frontend?
- How do security measures like browser sandboxing and CORS policy influence the division of labor between frontends and backends?
- What role does a reverse proxy like Nginx play in the request flow to a backend application?