Different Ways of Client-Server Communication
Understand the foundational client-server communication models including HTTP, RPC, and WebSocket protocols. Learn how each method functions, their benefits and limitations, and their roles in building efficient, real-time, and scalable APIs. Master HTTP versions evolution and practical usage for API design.
We'll cover the following...
- The World Wide Web and client-server foundations
- Hypertext Transfer Protocol (HTTP)
- HTTP message flow
- HTTP methods
- HTTP headers
- Significance of HTTP in APIs
- Evolution of HTTP
- Remote Procedure Calls (RPCs)
- What is an RPC?
- How RPC works
- RPC advantages
- RPC disadvantages
- WebSockets
- What is a WebSocket?
- How WebSocket works
- WebSocket advantages
- WebSocket disadvantages
The World Wide Web and client-server foundations
The internet is a global network of computers that communicate via standardized protocols. The World Wide Web (WWW) refers to interlinked resources stored across these machines, which are broadly accessed by clients (requesting resources) and servers (providing them). This communication relies on APIs built atop foundational protocols. Three protocols cover the major abstractions of client-server communication: HTTP, RPC, and WebSockets.
The WWW is a hypertext-based information system that interlinks documents across millions of machines. Launched at CERN in 1989 from Tim Berners-Lee's proposal, its first text-based prototype led to Marc Andreessen's Mosaic graphical browser in February 1993, catalyzing the web's transformation of information sharing and networking.
What is the difference between the internet and the web?
Core web concepts
The web rests on four foundational ideas:
Client-server model: The client requests a resource; the server provides it. For example, a browser (client) queries a DNS server for the IP address of www.educative.io, and receives 104.18.3.119.
Resource identifiers: A unique identifier locates resources (files, documents) over the internet. For example, https://www.educative.io/courses/grokking-modern-system-design-software-engineers-managers/g7EwEyNnR6D points to a specific lesson.
Hypertext and hypermedia: Hypertext contains nonlinear links between documents. Hypermedia extends this with multimedia content (graphics, video, audio, and interactive elements).
Markup language: A set of symbols inserted in a text document to define its structure, formatting, and connections between parts (e.g., HTML).
Note: Browsers render web pages by parsing markup languages, such as the one described above.
Web protocols
The client-server model requires well-defined protocols for interoperable communication. The client (typically a browser) displays data received from the server as a web page, with information flow governed by the Hypertext Transfer Protocol (HTTP).
Application-layer protocols like FTP, SMTP, and HTTP rely on lower-layer protocols (TCP, UDP, and IP) to deliver services to end users.
How the web works
From a user's perspective, the web is a collection of pages containing links to
Every device is identified by an Internet Protocol (IP) address. When a client sends a request, the server responds to the same client, identified by a five-tuple (source IP, source port, protocol number, destination IP, and destination port). The browser then renders the received data as a web page.
Client-side process
Resources are identified using a Uniform Resource Identifier (URI) consisting of three parts:
Protocol: e.g., HTTPS, used to fetch the web page.
Domain name: The DNS name that indicates where the resource is located.
Unique path: Determines the specific resource within a domain.
The browser fetches a web page through the following sequence:
The browser determines the URL, e.g., www.educative.io.
It queries the DNS server for the corresponding IP address.
The DNS server returns the web server's IP address.
The browser establishes a TCP connection with that IP address.
The browser sends an HTTPS request for the web page.
The server responds. If the page contains URLs for additional objects, the browser fetches them using the same process.
The browser renders the web page.
TCP connections are terminated after all resources are fetched.
Server-side process
Servers constantly listen for client requests. Upon receiving one, the server retrieves the resource from a database or cache and returns it:
Accept a TCP connection from the client.
Receive the request for a resource identified by a unique URI.
Populate the web page from the database or cache.
Send the content back as an HTTP response.
Terminate the TCP connection.
What’s the difference between static and dynamic web pages?
Hypertext Transfer Protocol (HTTP)
With the web's client-server model established, the protocol governing their communication deserves closer examination. The Hypertext Transfer Protocol (HTTP) is a
HTTP operates on a request-response model: the client sends HTTP commands, and the server responds with documents. These commands are structured by different API architecture styles discussed in later chapters. As long as a request conforms to HTTP standards, the server responds regardless of client type, enabling cross-platform interoperability.
HTTP message flow
HTTP communication begins ...