LunaNotes

Understanding Backend Architecture: How Requests Travel and Why Backends Matter

Convert to note

What is a Backend Server?

A backend server is a computer listening on open network ports (such as 80 or 443) to handle HTTP, WebSocket, or gRPC requests from clients or frontends. It serves content like static files (images, JavaScript, HTML) or dynamic data (JSON) and processes incoming data submissions.

Tracing a Request: Browser to Backend Server

  • Domain Resolution via DNS: The browser begins by resolving the domain name through the DNS server, which contains records pointing subdomains to specific IP addresses. This is part of The Hidden Magic Behind Accessing Your Favorite Websites.
  • AWS EC2 Instance: The resolved IP points to an AWS EC2 instance where the backend server is hosted. For more on key AWS services, see Top AWS Services Explained for Beginners: EC2, S3, IAM & More.
  • Firewall and Security Groups: Incoming requests must pass AWS security groups that define allowed ports such as HTTP (80) and HTTPS (443). If these ports are blocked, requests never reach the server.
  • Reverse Proxy (NGINX): NGINX acts as a reverse proxy on the EC2 instance, listening on standard ports and forwarding requests to the node server running locally (e.g., on port 3001). This setup provides centralized management of SSL certificates and request routing.
  • Node Server: The actual backend application runs as a Node.js process, handling the request, performing necessary logic, and sending back responses. To understand more about how Node.js servers handle requests and HTTP nuances, refer to Comprehensive Guide to HTTP Protocol and Express.js for Web Developers.

Why Do We Need Backends?

Backends centralize data handling and processing. For example, when you "like" a post on Instagram:

  • Your action sends a request to the backend.
  • The backend identifies you and the post owner.
  • It updates the database to record the like.
  • It triggers notifications to the post owner. This centralized management is essential for consistent data integrity, user-specific customization, and synchronization.

Why Not Put Backend Logic in the Frontend?

  • Security Restrictions: Browsers run code in sandboxed environments restricting file system access and limiting what external APIs can be called due to CORS policies.
  • Limited Database Access: Browsers cannot maintain persistent database connections or run native database drivers, which require socket connections and connection pooling.
  • Performance Constraints: Frontend devices vary widely in computing power; complex business logic and heavy data processing could cause lag or crashes.
  • Connectivity and Resource Management: Backend servers efficiently handle thousands of requests with connection pooling and optimized resource usage.

How Frontends Work Differently

Frontends (like a Next.js app) serve HTML, CSS, and JavaScript files to browsers. The browser fetches these resources, applies styles, and executes JavaScript to manage user interactions locally. This means the browser runs the code, unlike a backend, which processes requests centrally. For a deeper dive into the browsing and data travel process, see The Hidden Magic Behind Browsing: How Your Data Travels the Internet.

Summary of Request Journey

  1. Browser requests domain.
  2. DNS resolves domain to IP.
  3. Request passes AWS firewall (security group).
  4. NGINX reverse proxy receives request.
  5. NGINX redirects request to Node.js backend on localhost.
  6. Backend processes data, interacts with databases, and sends response.
  7. Response reaches browser.

Understanding this flow clarifies the distinct roles of frontend and backend components, the need for backend servers, and the architectural decisions guiding their design and deployment. This knowledge forms a strong foundation for learning backend engineering principles and best practices. To explore architectural principles further, consider reading Understanding Hexagonal Architecture: Transforming MVC Applications.

Heads up!

This summary and transcript were automatically generated using AI with the Free YouTube Transcript Summary Tool by LunaNotes.

Generate a summary for free
Buy us a coffee

If you found this summary useful, consider buying us a coffee. It would help us a lot!

Let's Try!

Start Taking Better Notes Today with LunaNotes!