Complete DevOps Bootcamp: Master DevOps in 12 Weeks
System DesignAPI communication

What is an API

API stands for Application Programming Interface. It is a set of endpoints exposed by an application that allows other applications (or frontends) to communicate with it, access its data, and perform operations without needing direct access to the underlying database. API_Flow

Why Do We Need APIs?

The Problem Without APIs

  • If a new application needs data from an existing application, giving direct database access is dangerous.
  • Direct access requires handling complex database queries.
  • Critical data might accidentally get deleted, affecting all applications using the same database.
  • Each new consumer would need to understand the internal database schema.

The Solution — APIs

  • The existing application exposes endpoints that provide controlled access to its data.
  • New applications call these endpoints to read, write, or modify data safely.
  • The API acts as a protective layer between external consumers and the database.

Real-World Analogy

Consider a restaurant.

  • Customer → Places order
  • Waiter → Takes request to kitchen
  • Kitchen → Prepares food
  • Waiter → Returns response

Here:

Real WorldSoftware World
CustomerClient Application
WaiterAPI
KitchenBackend Server/Database

The customer never directly enters the kitchen.

Similarly:

  • frontend applications do not directly access databases,
  • they communicate through APIs.

Common Use Cases of APIs

Use CaseDescription
Inter-application communicationOne application accesses data from another through APIs instead of duplicating databases
Frontend-Backend communicationBackend exposes APIs that web and mobile frontends consume to display data

A single backend can serve multiple frontends (web, mobile, desktop) through the same set of APIs.

API_Example


Types of APIs

REST API

REST — Representational State Transfer

AspectDetail
Data FormatJSON (JavaScript Object Notation)
Why PopularSimple structure, easy to use, lightweight, handles large data with low volume
UsageMost widely used in modern applications
  • REST organizes endpoints around resources (e.g., /users, /products, /orders)
  • Uses standard HTTP methods: GET, POST, PUT, DELETE
  • JSON is lightweight and human-readable, making it the preferred data exchange format

SOAP

SOAP — Simple Object Access Protocol

AspectDetail
Data FormatXML
Use CaseCross-platform communication, legacy systems
DrawbackXML is bulky, attributes and tags must be repeated for every object and array
  • Primarily found in legacy/enterprise applications
  • Largely replaced by REST in modern systems due to XML's verbosity

GraphQL

GraphQL — Graph Query Language

AspectDetail
Data FormatJSON
Key FeatureSingle endpoint for all queries
Query StyleClient specifies exactly what data it needs using a query language (similar to SQL)
  • Instead of hitting multiple REST endpoints, the frontend sends a single query describing exactly what data it needs.
  • Reduces over-fetching (getting more data than needed) and under-fetching (needing multiple calls).
  • Ideal when frontends have varying data requirements from the same backend.

gRPC

gRPC — Google Remote Procedure Call

AspectDetail
Data FormatProtocol Buffers (Protobuf)
Created ByGoogle
Key FeatureExtremely small payload size and fast data transfer
  • Protocol Buffers are significantly smaller and faster than both JSON and XML.
  • Ideal for microservice-to-microservice communication where low latency is critical.
  • In microservice architectures, multiple sub-applications communicate frequently — gRPC enables this internal communication to be fast and efficient.

WebSockets

WebSockets — Persistent bidirectional communication channel

AspectDetail
Key FeatureReal-time, two-way communication between client and server
Use CasesChat applications, live notifications, real-time updates

How WebSockets Work:

  1. Frontend initiates a request → a persistent channel is established.
  2. Once the channel is open, both sides can send data at any time.
  3. The backend can push notifications, messages, or updates to the frontend without being asked.

Why WebSockets Matter:

Without WebSocketsWith WebSockets
Frontend must constantly poll the backend asking "Any new data?"Backend pushes data to frontend whenever something new arrives
Wasteful network callsEfficient, event-driven communication
Higher latency for real-time featuresInstant delivery of messages and notifications

API_Comparison


Summary

  • APIs provide controlled, secure access to application data without exposing the database directly.
  • REST is the most widely used API type due to its simplicity and JSON-based communication.
  • SOAP is legacy and uses verbose XML — mostly found in older enterprise systems.
  • GraphQL solves over-fetching and under-fetching by letting clients request exactly what they need through a single endpoint.
  • gRPC uses Protocol Buffers for ultra-fast, lightweight communication — ideal for internal microservice calls.
  • WebSockets enable real-time, bidirectional communication — essential for chat, notifications, and live updates.

Written By: Muskan Garg

How is this guide?

Last updated on