Introduction

APIs provide services by exchanging information between client and server processes. The underlying network stack usually abstracts this interprocess communication, but how is it done? Popular API technologies such as RESTful, GraphQL, and gRPC work differently, but at the most basic level, they all use socket interfaces for process identification, connection establishment, and interprocess communication.

Let’s see the basic requirements for successful communication between two processes or services that operate on separate networked devices:

  • Identification of devices on the internet.

  • Identification of processes on the communicating devices.

  • Steps or procedures to exchange data between those processes.

Let’s understand how sockets play an important role in maintaining these three requirements.

What is a socket?

A socket is an interface that creates a two-way channel between processes communicating on different devices. Processes running on the application layer use sockets as an interface to take services from the transport layer to establish communication. Further, the interfacing requires an IP address and a port number to uniquely identify a process or application globally. The interface (IP address + port) is referred to as a socket address.

Two different sockets (endpoints) are required for any two processes to communicate. Each process in a connection is recognized by its respective socket address. The diagram below shows how “Process A" from a machine with "IP 1" can communicate with the “Process X" on another machine with "IP 2."

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.