Back to journal
Web Development4 October 202616 min read

Frontend vs Backend vs Database: How Web Applications Actually Work

Learn how frontend, backend, APIs, and databases work together in a web application, with real-world examples, code, and architecture diagrams.

Written by Abhijeet Kulkarni

Article
In this article

Frontend vs Backend vs Database: How Web Applications Actually Work

Subtitle: A beginner-friendly guide to understanding the frontend, backend, APIs, and databases that power modern web applications.

Every time you log in to an application, place an order, book a table, or send a message, multiple software components work together behind the scenes.

But have you ever wondered what actually happens after you click a button?

How does the application process your request? Where is your information stored? And how does the result appear on your screen within seconds?

To understand these interactions, you need to understand four fundamental concepts of web development:

  • Frontend: The interface users interact with.
  • Backend: The server-side logic that processes requests.
  • API: The interface that allows software components to communicate.
  • Database: The system that stores and retrieves information.

Let's explore each component with examples, diagrams, and code.

Frontend, backend, API and database in web development
Frontend, backend, API and database in web development

1. What Is the Frontend?

Subtitle: Everything users see and interact with.

The frontend is the part of a web application that runs primarily in the user's browser and provides the interface for interacting with the application.

It includes buttons, navigation menus, forms, animations, dashboards, product listings, and everything else users see on the screen.

For example, when you open an e-commerce website, the following elements belong to the frontend:

  • Product images and descriptions
  • Search bars and filters
  • Add to Cart buttons
  • Shopping cart and checkout pages
  • Login and registration forms
  • Navigation menus and animations

The frontend is responsible for presenting information and collecting user input. When it needs information or wants to perform an operation, it typically communicates with a backend through an API.

Technologies used in frontend development

Frontend web development code on a computer screen
Frontend web development code on a computer screen
TechnologyPurpose
HTMLDefines the structure of a webpage.
CSSControls styling, layout, and responsiveness.
JavaScriptAdds interactivity and dynamic behavior.
ReactBuilds interfaces using reusable components.
Next.jsProvides a React framework for routing, rendering, and full-stack web development.

Example: A simple frontend button

Consider an online store with an Add to Cart button.

function AddToCartButton() {
  function handleClick() {
    console.log("Product selected");
  }

  return (
    <button onClick={handleClick}>
      Add to Cart
    </button>
  );
}

export default AddToCartButton;

When the user clicks the button, JavaScript executes the event handler.

This example only handles the click locally. A real shopping cart would also update the cart state and might send a request to the backend to persist the change.

Key takeaway: The frontend handles the user experience, but it should not be trusted to enforce critical business rules or permissions.

2. What Is the Backend?

Subtitle: The engine that processes requests and runs business logic.

The backend is the server-side part of an application. It receives requests, validates input, applies business rules, communicates with databases, and returns responses.

Imagine clicking the Add to Cart button on an online store.

The frontend can send a request to the backend. The backend can then:

  1. Identify the user.
  2. Validate the requested product.
  3. Check product availability.
  4. Apply relevant business rules.
  5. Store or update the cart.
  6. Return a response to the frontend.

The backend is also responsible for operations such as authentication, authorization, order processing, payment integration, notifications, and external service integrations.

Backend server infrastructure
Backend server infrastructure

Technologies used in backend development

TechnologyCommon use
Node.jsRunning JavaScript on the server.
Express.jsBuilding HTTP APIs with Node.js.
FastifyBuilding lightweight, high-performance Node.js APIs.
PythonImplementing server-side logic and automation.
FastAPIBuilding APIs in Python.
DjangoDeveloping Python web applications.
Java with Spring BootBuilding enterprise backend systems.
PHP with LaravelDeveloping web applications and APIs.

Example: A backend API using Express

import express from "express";

const app = express();

app.use(express.json());

app.get("/api/products", (req, res) => {
  const products = [
    {
      id: 1,
      name: "Wireless Mouse",
      price: 799
    },
    {
      id: 2,
      name: "Mechanical Keyboard",
      price: 2499
    }
  ];

  res.json({ products });
});

app.listen(3000, () => {
  console.log("Server running on port 3000");
});

This backend exposes an endpoint that returns product data in JSON format.

For simplicity, the example uses an in-memory array. In a production application, the backend would typically retrieve products from a database.

Key takeaway: The backend processes requests and enforces the rules that determine what an application is allowed to do.

3. What Is a Database?

Subtitle: Where application information is stored and organized.

A database stores information so that an application can retrieve, update, and manage it when needed.

Consider an e-commerce application. It may need to store:

  • User accounts and profiles
  • Products and categories
  • Prices and inventory
  • Shopping carts
  • Orders and payment records
  • Shipping addresses

Without persistent storage, an application would struggle to maintain information between requests and user sessions.

Database and data storage infrastructure
Database and data storage infrastructure
DatabaseTypeCommon use
PostgreSQLRelationalBusiness applications, transactions, and structured data.
MySQLRelationalWebsites, e-commerce, and business systems.
MongoDBDocument-orientedApplications that use flexible document structures.
SQLiteRelationalLocal applications, prototypes, and embedded storage.

How does the backend communicate with a database?

Suppose a user opens a product page.

The backend queries the database for the relevant product. The database returns the matching record, and the backend sends the required information to the frontend.

For a relational database, a query might look like this:

SELECT id, name, price
FROM products
WHERE id = 1;

The database returns the matching product if it exists and the request is permitted.

The backend can then format the result into a response for the frontend.

Why shouldn't the frontend connect directly to a private database?

A private production database should generally be accessed through a trusted server-side layer or another carefully secured access mechanism.

Connecting a browser directly to a private database can expose credentials or allow unauthorized operations if access controls are not designed correctly.

The backend can authenticate requests, enforce permissions, validate data, and restrict which operations are available.

Key takeaway: The database stores the information, while the backend controls how the application accesses and changes it.

4. What Is an API?

Subtitle: How the frontend and backend communicate.

API stands for Application Programming Interface.

An API defines how one software component can request functionality or data from another component.

In a typical web application, the frontend sends an HTTP request to a backend API. The backend processes the request and returns a response, often formatted as JSON.

For example, a frontend might request a list of products using this endpoint:

GET /api/products

The backend could respond with:

{
  "products": [
    {
      "id": 1,
      "name": "Wireless Mouse",
      "price": 799
    },
    {
      "id": 2,
      "name": "Mechanical Keyboard",
      "price": 2499
    }
  ]
}

The frontend can use this response to display product cards on the page.

Common HTTP methods

MethodTypical purpose
GETRetrieve information.
POSTCreate a resource or initiate an operation.
PUTReplace a resource.
PATCHPartially update a resource.
DELETEDelete a resource.

The exact behavior depends on the API's design.

Example: Calling an API from the frontend

async function fetchProducts() {
  const response = await fetch("/api/products");

  if (!response.ok) {
    throw new Error("Failed to fetch products");
  }

  const data = await response.json();

  return data.products;
}

This function sends a request to the API, checks the HTTP response, and converts the JSON response into JavaScript data.

A React component could then use that data to render product cards.

Important: An API is a communication interface, not necessarily a separate server. A single backend application can expose many API endpoints.

Key takeaway: APIs define how components exchange requests and responses without requiring the frontend to know how the backend implements its internal logic.

5. How Do Frontend, Backend, API, and Database Work Together?

Subtitle: Follow a request from a button click to the final result.

Let's use a familiar example: placing an order on an e-commerce website.

Web application development and software architecture
Web application development and software architecture

Step 1: The user interacts with the frontend

The user selects a product, chooses a quantity, and clicks Checkout.

The frontend collects the necessary input and initiates the request.

Step 2: The frontend sends an API request

The frontend sends the order details to the backend.

For example:

POST /api/orders
Content-Type: application/json

The request body might contain:

{
  "productId": 1,
  "quantity": 2
}

The authenticated user's identity should come from a trusted authentication mechanism, not from blindly trusting an arbitrary user ID supplied by the browser.

Step 3: The backend validates the request

The backend checks whether the request is valid.

It may verify that:

  • The user is authenticated.
  • The product exists.
  • The quantity is valid.
  • The product is available.
  • The user has permission to perform the operation.

The backend should calculate the price using trusted product and pricing data instead of accepting a total supplied by the browser.

Step 4: The backend communicates with the database

The backend retrieves the product details and creates the order record.

A well-designed checkout flow also considers inventory consistency, duplicate requests, transaction handling, and payment processing.

For example, payment status should only be updated based on a trusted payment-provider response or verified webhook, not simply because the browser says payment succeeded.

Step 5: The backend sends a response

After processing the request, the backend returns an appropriate response.

For example:

{
  "success": true,
  "order": {
    "id": 1024,
    "status": "confirmed"
  }
}

The actual response depends on the application's design and whether the order has truly been confirmed.

Step 6: The frontend updates the interface

The frontend receives the response and displays the appropriate result.

The user might see an order confirmation page, an updated order history, or an error message explaining what needs attention.

The complete request-response flow

USER
 |
 v
FRONTEND
 |
 | HTTP request
 v
API ENDPOINT
 |
 v
BACKEND
 |
 | Database query
 v
DATABASE
 |
 | Query result
 v
BACKEND
 |
 | HTTP response
 v
FRONTEND
 |
 v
UPDATED USER INTERFACE

In a real application, the backend may also communicate with payment gateways, message queues, caches, or other external services.

Key takeaway: The frontend initiates interactions, the API carries requests and responses, the backend processes business logic, and the database provides persistent storage.

6. A Real-World Example: Restaurant Management Software

Subtitle: Understanding the architecture through an application used by real businesses.

Imagine a restaurant using a POS (Point of Sale) system to manage tables, menu items, orders, payments, and kitchen operations.

Each part of the application has a different responsibility.

Restaurant point of sale and order management
Restaurant point of sale and order management

How each component works

ComponentResponsibility
FrontendDisplays tables, menus, order details, and payment screens.
APIExposes endpoints for creating orders and retrieving information.
BackendValidates orders, calculates totals, applies discounts, and manages order status.
DatabaseStores menu items, tables, orders, and payment records.
WebSocketEnables real-time communication between connected clients and the server.

Example: A waiter creates an order

  1. The waiter selects a table on the POS interface.
  2. The frontend sends the order details to the backend.
  3. The backend validates the items and calculates the total.
  4. The database stores the order and its items.
  5. The backend publishes an order event.
  6. The kitchen screen receives the event and displays the new order.

Where do WebSockets fit in?

Traditional HTTP requests are commonly used when a client needs to retrieve or update information.

WebSockets provide a persistent, two-way communication channel between connected clients and a server. They are useful when updates need to be delivered without repeatedly polling an endpoint.

For example, when an order is confirmed, the backend can notify the kitchen screen that a new order is ready to be displayed.

POS FRONTEND
     |
     | Create order through API
     v
BACKEND
     |
     v
DATABASE
     |
     | Order saved
     v
BACKEND
     |
     | WebSocket event
     v
KITCHEN SCREEN
     |
     v
NEW ORDER DISPLAYED

The backend should ensure that the order is saved successfully before publishing an event that tells the kitchen to process it. Production systems may use a transactional outbox or another reliable event-delivery mechanism to avoid losing important updates.

This same architecture can support inventory management, logistics systems, CRM platforms, ERP software, and many other business applications.

Key takeaway: Once you understand these components, you can apply the same concepts to much more complex software.

7. Frontend vs Backend vs Database vs API

Subtitle: A quick comparison of their responsibilities.

FeatureFrontendAPIBackendDatabase
Main roleUser interfaceCommunication contractBusiness logicData storage
Typical locationBrowser or rendering serverInterface exposed by a serviceApplication serverDatabase server or managed service
Handles user interactionsYesNo, not by itselfProcesses resulting requestsNo, not by itself
Validates business rulesBasic client-side checksDefines request/response structureYesEnforces data constraints
Stores persistent dataNot normallyNo, not by itselfCoordinates storageYes
Example technologiesReact, Next.jsHTTP, REST, JSONNode.js, FastAPI, DjangoPostgreSQL, MySQL, MongoDB

These are logical responsibilities, not always separate machines or applications. For example, Next.js can handle frontend rendering and certain backend operations within one project.

8. What Should You Learn First?

Subtitle: A practical roadmap for becoming a full-stack developer.

If you're starting web development, you don't need to learn every framework or database at once. Build your understanding step by step.

Developer learning and building software
Developer learning and building software

Step 1: Learn HTML, CSS, and JavaScript

Understand page structure, layouts, responsive design, variables, functions, arrays, objects, and asynchronous JavaScript.

Build: A personal portfolio website.

Step 2: Learn React

Understand components, props, state, event handlers, forms, and how to fetch data.

Build: A product listing page with search and filtering.

Step 3: Understand HTTP and APIs

Learn request methods, status codes, headers, JSON, asynchronous requests, and error handling.

Build: A weather interface or product dashboard using an API.

Step 4: Learn backend development

Choose one backend stack, such as Node.js with Express or Python with FastAPI.

Learn routing, validation, middleware, authentication, and business logic.

Build: An API for managing products or tasks.

Step 5: Learn databases and SQL

Understand tables, relationships, primary keys, foreign keys, joins, indexes, and transactions.

Build: Store and retrieve your application's data using PostgreSQL or MySQL.

Step 6: Learn authentication and security

Understand sessions or tokens, password hashing, authorization, input validation, environment variables, and secure handling of sensitive information.

Build: A login system with protected resources.

Step 7: Build a complete full-stack application

Connect the frontend, API, backend, and database.

Build: A task manager, inventory system, restaurant POS, or mini CRM.

Finally, learn how to deploy the application, manage environment variables, monitor errors, and maintain it in production.

Key takeaway: Build real projects while learning. Each project will help you understand how the individual components fit together.

9. Frequently Asked Questions

Subtitle: Common questions beginners have about full-stack development.

Is frontend easier than backend?

They involve different challenges. Frontend development focuses on user interfaces, interactions, accessibility, and browser behavior. Backend development focuses on data, business logic, security, reliability, and system behavior.

The difficulty depends on the application and your experience.

Can a website work without a backend?

Yes. A static website can display content without a custom backend. Some interactive features can also run entirely in the browser.

However, features such as shared user accounts, centralized order processing, and persistent multi-user data typically require a backend or a managed service that provides equivalent functionality.

Can I use Next.js for both frontend and backend?

Yes. Next.js supports frontend rendering as well as server-side capabilities such as Route Handlers and Server Actions.

For larger systems, developers may still use a separate backend service for domain logic, background jobs, integrations, or multiple client applications.

Which database should a beginner learn?

A relational database such as PostgreSQL is a useful starting point because it teaches tables, relationships, SQL, joins, and transactions.

Other databases may be appropriate depending on the data model and application requirements.

Is an API the same as a backend?

No. The backend is the server-side application and its logic. An API is an interface through which other software can interact with a service.

A backend can expose multiple APIs, and an API can be implemented using many different technologies.

Conclusion

Modern web applications work because multiple components cooperate.

The frontend provides the interface. The API defines how components communicate. The backend processes requests and applies business rules. The database stores and retrieves information.

Understanding these responsibilities gives you a foundation for building everything from a simple website to a complete business management platform.

You don't have to master everything before you start. Pick a small project, connect these components, and learn by solving real problems.

The best way to learn web development is to build something real.

I'm Abhijeet Kulkarni, a developer and entrepreneur exploring software engineering, AI, automation, and digital products. I share what I learn while building real-world applications.

More practical web development guides are on the way.