DEV Community

Cover image for Building a Backend Brain #1: Demystifying Clients, Servers, and Ports
Cem Batuhan Yaman
Cem Batuhan Yaman

Posted on AI-assisted

Building a Backend Brain #1: Demystifying Clients, Servers, and Ports

Hey, beautiful internet people!

I thought for my very first post and article, the topic should be how the internet actually works and what happens behind the scenes!

I remember my early days on the internet, trying to figure out how programming even works and spending countless hours going down rabbit holes on this exact topic. Looking back, I realized it would be amazing to write an article breaking it all down, not just to share with others, but to really cement those fundamentals for myself.

This post is going to be the kickoff of a brand-new series where I'll be tackling system design, networking ideas, and sharing the core concepts that I've found most valuable on my journey.

Let's dive into the first one!

How the Internet Works: Clients, Servers, IP Addresses, and Ports

Before we go any deeper let's just see what's happening under the hood, every time you type a URL into your browser or fire a curl command into a terminal, an intricate dance of networking protocols and application code happens in milliseconds.
Understanding how a request travels from a client to a server, and how languages like Go handle it, is essential for any backend developer.

The Foundation: The Client/Server Model and Ports

It is important to understand that most devices and machines communicating over a network act as hosts, taking on the role of either a client or a server.

The primary difference lies in their roles during communication: clients initiate requests, while servers receive and respond to those requests.

A diagram that shows the connection between servers and clients

Keep in mind that these roles are relative to a particular interaction. A server, for example, can act as a client when requesting resources or services from another server.

While clients initiate requests, servers run software designed to receive, process, and respond to those requests.

So:

  • A host is not necessarily a client or server at all times. A host is a network-connected device or system that can communicate over a network. Client and server describe roles that software takes in a particular interaction.
  • A server is not necessarily a dedicated computer. Server software can run on an ordinary laptop, a virtual machine, or a cloud instance.
IP Addresses: Where Does the Data Go?

Now that we understand who's talking to whom, there's another question:

How does the network know where to send the information

An IP (Internet Protocol) address is a numerical address assigned to a network interface, allowing devices to communicate over IP networks, including the internet.

When a client sends a request to a server, the data is packaged into IP packets containing two important pieces of information: a source IP address and a destination IP address.

Think of these as the sender's and recipient's addresses on a letter. The destination address helps the network determine where the packet should go, while the source address identifies where it came from.

Now, I don't want to bore you to death with technical details, but there is something worth understanding about how these addresses are structured.

There are two versions of IP addresses in widespread use today: IPv4 and IPv6. For now, we'll focus on IPv4.

An IPv4 address consists of 32 bits, divided into four groups of 8 bits called octets. Each octet is represented as a decimal number ranging from 0 to 255.

I know, I know, this sounds like a lot, but I promise it's not that complicated!

Imagine it like this:

  • 1 octet = 8 bits
  • 4 octets = 32 bits
  • each octet = a decimal value between 0 and 255

For example, 192.168.1.10 is a valid IPv4 address.

We'll leave IPv6 and the more complicated details of IP addressing for another time.

Ports: Finding the Right Application

Alright, so we know how a packet can find its destination.

But here's another question: What if that machine is running multiple network applications? How does incoming traffic reach the right one?

That's where ports come in.

Think of an IP address as the address of an apartment building and a port number as an apartment number.

The IP address helps traffic reach the correct destination, while the port number helps the operating system deliver it to the appropriate application endpoint.

Ports are represented by numbers ranging from 0 to 65535.

Some common examples include:

  • 80 <--> HTTP
  • 443 <--> HTTPS
  • 8080 <--> Commonly used by development servers
  • 3030 <--> Another popular port for local development

These port numbers are used by transport protocols such as TCP and UDP, which we'll explore in the next article.

Wrapping Up

And that's it for our first introduction!

Today, we've established three fundamental ideas:

  • Clients and servers describe the roles software performs during communication.
  • IP addresses help networks deliver packets to their destinations.
  • Ports help identify the appropriate application endpoint on a host.

Of course, there's much more happening behind the scenes.

We've only scratched the surface!

In the next article, we'll explore TCP, how connections are established, and how HTTP requests travel between clients and servers.

See you in the next one!

Top comments (0)