Understanding Network Devices

What is Modem and How It Connects Your Network To The Internet?
MODEM is short for Modulator Demodulator, which means a device that converts the analog signal of the internet cables that come to your home into a digital signal (Binary 1s and 0s). The computer can only work with a digital signal, which is provided by the modem through the conversion from analog to digital.
Incoming Data (Demodulation / Decoding):
When Netflix sends a movie video stream to your computer through the internet to your ISP, who sends it to your house using a cable. MODEM uses this physical signal and demodulates it, converting it into digital signal(Binary 1s and 0s) and sends the stream to your computer through a router or ethernet cable.
Outgoing Data (Modulation / Encoding):
When you click upload on Instagram to post an image, the image is sent from your device to the modem through a digital signal. This signal is then converted into a physical signal, which is sent to the ISP, who then sends the same analog signal to the Instagram servers.
Modem brings the internet into your house, it establishes a connection to ISP. While the router supplies the internet to your devices in the house
Internet → Modem → Router → Switch → Devices flow:

What is a Router and How It Directs Traffic?
We have seen how internet reaches from ISP to modem and gets decoded and is sent to the router to transmit it to various devices in the house. The primary role of router is to connect the two different networks together, Wide Area Network(WAN) (Internet) to the Local Area Network(LAN) in your house. Router acts as a decision point between WAN and the LAN. Every time a new connection is made router takes care of the transactions between your computer and the internet.
Router acts as the mediator between the internet and the devices. When any data is received on the modem it does not know which devices to send this data to, those data packets come with a destination IP address, router checks if that IP address in present in it’s LAN, if it is available then the data is sent to the respective device. Without router, every device in a LAN would get every data, even the one that is not meant for it.
Incoming Data:
When data incoming is under process, the data comes to the router in the form of packets. Every packet contains a destination address. It is the IP address where the data is supposed to end up.
Router check if the address is present in my LAN?
If Yes → Send the data to the respective device.
Router sends the data to that device only, without router every device would get all the data.
Outgoing Data:
When you press the upload on Instagram, packets of data are created with Source address(Your IP address) and the destination address(Instagram server). This is when the router check if the destination address is present in my LAN, if not then router sends the data to the MODEM and then IP and then to the internet.
Router is like a traffic police standing at the door of your house taking care of all the interactions you are going to have. If you order a pizza and the pizza deliver guy comes then how would he know where to deliver the pizza in a large building, this is where traffic police(router) check that you ordered the pizza and he takes the pizza from the guys and delivers it to you personally. This is why your computer is "safe" behind a router. If a bad delivery guy comes to the building, the Router stops them at the door and says, "Nobody ordered this," and sends them away. They never get near your actual room.
Switch vs Hub: How Local Networks Actually Work?
Hub is a multi-port repeater. It send any received data to all the devices by default. It works in a way like one to many fashion. When a laptop A wants to send data to laptop B using hub, what hub does is it takes the data sends it to device B and also to every other device like laptop C, D E, etc.
Switch intelligently transfer the data to the correct device using the MAC address(It is the hardware based address concerned with every network card). The data in switch is wrapped around Ethernet frame so that it can travel in LAN. This Ethernet frame has a source MAC address and the Destination MAC address and the payload(actual data)
| Switch | Hub |
| 1. Sends data to the correct device in LAN | 1. Sends data to every device in LAN |
| 2. Other devices do not see the data | 2. Every device processes every frame |
| 3. Collisions are basically eliminated | 3. Collisions are very common due to sending data to multiple devices at the same time |
| 4. Security is very high compared to hub as every device sees only its own traffic | 4. Security is lower compared to switch as every device sees all the data |
What is a Firewall and why security lives here?
Firewall works as the gatekeeper, who takes care of the packets that are going to enter the network. It sits between the secure network(LAN) and the untrustworthy network(Internet). It check if a certain data is allowed to go into the secure network and also the outgoing traffic from our current secure network. Firewall takes care of inspection and decision. It checks things like the source address, destination address, port, etc. Firewall also control the apps that can access the internet and the servers that can talk to the databases. It prevents data leaks. There are two kinds of firewalls, there is a software firewall which comes in-build in most of the latest computers and there is a hardware firewall which is used to protect the servers from unwanted visitors and threats.
The network Firewall and a real structural firewall work in a similar fashion, where a structural firewall works by containing the fire in a building and avoiding it from spreading and causing more damage. Similarly, network firewall also has a fire to avoid entering our secure network and that fire in our case is the internet which is full of threats, hackers and viruses. The network firewall filters the incoming packets by their IP-addresses, certain addresses are allowed while the traffic from some addresses is filtered out or stopped from entering the network. The firewall does not filter out only on the basis of IP-addresses but also on the basis of other factors like domain names, ports, protocols and even keywords.


What is a Load Balancer and why scalable systems need it?
Load Balancer the name itself is self explanatory. It works to reduce the load on servers by distributing requests across available servers, so no one server gets load of client requests.In case a server goes down, the load is redirected to the other active servers. If a new server is added to the network, then the same load is redistributed among those servers. Since load balancer works with multiple server, the client get their request readily addressed even when certain servers might be down.
Load balancer is widely used in the development market, an example to explain it is that during diwali sale or yearend sale, the ecommerce websites get a really heavy traffic and this is when load balancer plays an important role by delegating the requests between all the available servers and providing a smooth experience to the users. Load balancer allows to dynamic addition or removal of servers from the network, ensuring that the system remains scalable. The main reason a load balancer is needed is because if a single server is used it gets bottlenecked and overwhelmed by large number of requests, to avoid this several servers are used along with a load balancer.

How all these devices work together in a real-world setup?
The internet comes to your home in network cables in form of physical signal which is decoded by the modem. Modem converts the physical signal received from the ISP to digital signal. Next comes the router which mostly has inbuilt firewall, so the router acts as the distributor for the internet packets, while the firewall acts as a safeguard which protects our system and network from threats and unwanted visitors. After all of this process, your open a website and your request leaves the computer. The request hits the website’s load balancer, which delegates the requests to various available servers. That server processes the request and the response travels the same path back. Modem, Router, Firewall, Switch, Hub are the part of our LAN, while the load balancer is an external device used at servers and users interact with the load balancer and the same load balancers deals with selecting a server for your request subject to availability of servers.





