-
Notifications
You must be signed in to change notification settings - Fork 0
Networking & Protocols


In Remote Procedure Call a client causes a procedure to execute on a different address space, usually a remote server and the procedure is coded as if it were a local procedure call, abstracting away the details of how to communicate with the server from the client program. It is about executing a block of code on another server, and when implemented in HTTP or AMQP it can become a Web API.
- Client program - Calls the client stub procedure. The parameters are pushed onto the stack like a local procedure call.
- Client stub procedure - Marshals (packs) procedure id and arguments into a request message.
- Client communication module - OS sends the message from the client to the server.
- Server communication module - OS passes the incoming packets to the server stub procedure.
- Server stub procedure - Unmarshalls the results, calls the server procedure matching the procedure id and passes the given arguments.
- The server response repeats the steps above in reverse order.
- RPC is focused on exposing behaviors. The client must know which methods (endpoints) to hit at what time, in order to construct its own workflow
- SOAP is a type of RPC.
- A modern RPC implementation is gRPC It uses a data format called ProtoBuff, which requires a schema as well as the data instance, much like the WSDL in SOAP.
- GRPC focuses on making single interactions as quick as possible, thanks to HTTP/2, and the fact that Protobuff packs down smaller than JSON.
- gRPC is built on top of HTTP/2, which supports bidirectional communication along with the traditional request/response. In practice, the client opens a long-lived connection with the gRPC server and a new HTTP/2 stream will be opened for each RPC call.
- In HTTP 1.1, when multiple requests come from multiple clients, they are served one by one. This can slow down the system. HTTP 2 allows multiplexing, so multiple requests and responses can be served at the same time.
- Other alternatives to protobuff are Thrift and Avro.
- When a transaction crosses a bounded context then it is not advisable to use RPC
Representational State Transfer - The server provides a representation of resources and actions that can either manipulate or get a new representation of resources. All communication must be stateless and cacheable. There are four qualities of a RESTful interface:
- Identify resources (URI in HTTP) - use the same URI regardless of any operation.
- Change with representations (Verbs in HTTP) - use verbs, headers, and body.
- Self-descriptive error message (status response in HTTP) - Use status codes, don't reinvent the wheel.
- HATEOS(HTML interface for HTTP) - your web service should be fully accessible in a browser. It is essentially just the concept of providing "next available actions", which could be related data in the form of links
Architectural Constraints
- Uniform interface: Meaning API interfaces must be present to the resources in the web application to the consumers of the API.
- Client-server: The client and server must be independent of each other, and the client should only know the URIs to the resource.
- Stateless: The server must not store anything related to the client request. The client is responsible for maintaining the state of the application.
- Cacheable: The resources must be cacheable.
- Layered system: The architecture must be layered, meaning the components of the architecture can be in multiple servers.
-
REST can theoretically work in any transportation protocol that provides it the ability to fulfill the constraints, but no transportation protocol other than HTTP has the functionality, ex being able to provide hypermedia controls in response. Disadvantages:
-
Resources with complex hierarchies will require multiple round trips (over fetching and under fetching issues)
-
Not a good fit if data is not organized as resources. Ex; Questionnaire API
-
Certain operations may not fit within available HTTP verbs. Ex. Move expired docs to archive
-
For complex business processes spanning multiple resources, we can consider the business process as a resource itself. For example, the process of setting up a new customer in a banking domain can be modeled as a resource.
-
One of the key switches in thinking is to understand that there is an infinite URI space that you can take advantage of. At the same time, it is good to avoid resource proliferation that may add confusion to the API design. As long as there is a genuine need for the resources with clear user/consumer “intent” that fits well in the overall API design, URI space can be expanded
-
REST interfaces commonly use PUT to update resource state, however it's often better to POST to record a new event resource which captures intent. REST without PUT has a side-benefit of separating command and query interfaces and forces consumers to allow for eventual consistency.
Domain Name System / Services(DNS) -Are responsible for translating mnemonic textual Internet addresses into hard numeric Internet addresses
Ports -An IP address identifies a host machine on the Internet. -An IP port will identify a specific application running on an Internet host machine.
Types of Networks - WAN & LAN
Examples of WAN technology: Asynchronous Transfer Mode (ATM), Integrated Services Digital Network (ISDN) Examples of LAN technology: Ethernet, Token Ring, and Fibber Distributed Data Interconnect (FDDI).
Networks interconnection is achieved using one or several of the following devices: →Bridge: a computer or device that links two similar LANs based on the same protocol. → Router: a communication computer that connects different types of networks using different protocols. → B-router or Bridge/Router: a single device that combines both the functions of bridge and router. → Gateway: a network device that connects two different systems, using direct and systematic translation between protocols.
OSI Layers
- Physical layer (defines the physical characteristics of the network) - ensures a safe and efficient travel of data; consists of electronic circuits for data transmission etc.
- Data-link layer (provides safe communication of data over the physical network) - in charge of data encapsulation under the form of packets and their interpretation at the physical layer.
- Network layer (handles connection to the network by the higher layers) - in charge of packets transmission from a source A to a destination B.
- Transport layer (provides end-to-end errors detection and correction) - in charge of the delivery of packets from a source A to a destination B
- Session layer (manages sessions among applications) - in charge of the management of network access.
- Presentation layer (provides standard data representations for applications) - determines the format of the data transmitted to applications, data compressing/decompressing, encrypting etc.
- Application layer (applications connected to the network) - contains the applications which are used by the end-user, such as Java, Word etc.


The TCP/IP Model -Consists of only 4 layers: application, transport, internet and network.
Internet Protocol (IP)
- Overview -The IP protocol provides two main functionality: →Decomposition of the initial information flow into packets of standardized size, and reassembling at the destination. →Routing of a packet through successive networks, from the source machine to the destination identified by its IP address
- IP is connectionless and does not guarantee delivery.
Transmission Control Protocol (TCP) -TCP provides by using IP packets a basic service that does guarantee safe delivery: →error detection →safe data transmission →assurance that data are received in the correct order -Before sending data, TCP requires that the computers communicating establish a connection (connection-oriented protocol). -TCP provides support for sending and receiving arbitrary amounts of data as one big stream of byte data (IP is limited to 64Kb). -TCP does so by breaking up the data stream into separate IP packets. -Packets are numbered, and reassembled on arrival, using sequence and sequence acknowledge numbers. -TCP also improves the capability of IP by specifying port numbers. → There are 65,536 different TCP ports (sockets) through which every TCP/IP machine can talk.
User Datagram Protocol (UDP) -Datagram protocol also built on top of IP. -Has the same packet-size limit (64Kb) as IP, but allows for port number specification. -Provides also 65,536 different ports. -Hence, every machine has two sets of 65,536 ports: one for TCP and the other for UDP. -Connectionless protocol, without any error detection facility. - Error detection is the responsibility of the receiving application. -Provides only support for data transmission from one end to the other, without any further verification. -The main interest of UDP is that since it does not make further verification, it is very fast. -Useful for sending small size data in a repetitive way such as time information.
HTTP is a protocol that is an abstraction built on top of TCP/IP. It introduces a very important pattern called the request-response pattern, specifically for client-server interactions.
HTTP 1.1 vs 2:
- HTTP1.1 is limited to processing only one request per TCP connection, forcing browsers to use multiple TCP connections to process multiple requests simultaneously.
- HTTP 2 provides multiplexed streams i.e. multiple bidirectional sequence of data exchange. This allows client and server to disintegrate the HTTP payload into small, manageable sequence of frames which can be reassembled at the other end.
- Server push - allows the server to send additional cacheable information to the client that isn’t requested but is anticipated in future requests.
- Other benefits in HTTP2 are Stateful header compression (where headers are compressed to reduce network stream size) and Stream prioritization
- Features such as fewer TLS handshakes, low resource consumption on both client and server sides and improved capabilities in reusing existing web sessions while eliminating vulnerabilities associated with HTTP1.x make HTTP2 superior
ICMP stands for internet control message protocol. It is used to send messages between devices to indicate the availability or error conditions. These packets are used in a variety of network diagnostic tools, such as ping and traceroute.
IPv4 & IPv6
- 32 bit vs 128 bit addressing
- 32 bit - 4 8-bit segments separated by ‘.’ As it is 8 bit each can have values 0-255 (2^8)
- IPv4 addresses were traditionally divided into 5 classes A thru E which are defined by the first four bits of the address.
- Class A: 0_ i.e. 1st bit is 0. Range 0.0.0.0 too 127.255.255.255
- Class B: 10_ Range 128.0.0.0 to 191.255.255.255
- Class C: 110_ Range 192.0.0.0 to 223.255.255.255
- Class D: 1110 Range 224.0.0.0 to 239.255.255.255
- Class E: 1111 range 240.0.0.0 to 255.255.255.255
- Class D & E are reserved
- Traditionally, each of the regular classes (A-C) divided the networking and host portions of the address differently to accommodate different sized networks. However this method is not used anymore
- Each of the normal classes also have a range within them that is used to designate private network addresses. For ex, for class A, 10.0.0.0 to 10.255.255.255 are private. Similarly 172.16.0.0 to 172.31.255.255 and 192.168.0.0 to 192.168.255.255 for classes B & C.
The process of dividing a network into smaller network sections is called subnetting. Each address space is divided into a network portion and a host portion. The amount the address that each of these take up is dependent on the class. For ex, for Class C the first 3 octets are used to describe the network and the last one for host. A netmask is basically a specification of the amount of address bits that are used for the network portion. A subnet mask is another netmask within used to further divide the network. Netmask is usually represented as, for ex., 255.255.255.0 - this means the first 24 bits are for network and last 8 bits are for the host.
CIDR -
- Classless Inter-Domain Routing, was developed as an alternative to traditional subnetting. The idea is that you can add a specification in the IP address itself as to the number of significant bits that make up the routing or networking portion.
- In CIDR notation we express IPs as, for example, 192.168.0.15/24 . Here the /24 indicates that 24 bits are reserved for network.
- A network can be subdivided further. For instance, a network 134.122.0.0./16 can be subdivided into /19 networks.
- This means an additional 3 bits are re- allocated for the network and this provide us with 2^3 or 8 networks in addition.
- The netmask in binary would be 19 ones followed by 13 zeros which can be represented in hex as 0xFFFFE000. Hence the netmask would be 255.255.224.0.
- This network would have 32-19=13 bits for hosts. Therefore we would get 2^13-2 = 8190 hosts.
- The network addresses of the 8 networks would be
134.122.0.0 134.122.32.0 134.122.64.0 134.122.96.0 134.122.128.0 134.122.160.0 134.122.192.0 134.122.224.0- To calculate the above, we need to change the value of the first 3 bites in the 3rd octet. Ex: 0000 0000, 0010 0000, 0100 0000 etc..
DHCP - Dynamic Host Configuration Protocol
- Provides a mechanism for automatically allocating IP (IPv4) addresses to network devices
- The DHCP server is configured with a range of IP addresses that it can assign and also with other settings like DNS servers, default gateway addresses etc.
- IP addresses from a DHCP server are normally leased, and must be renewed periodically.
DNS


NAT or Network Address Translation, allows the addresses to be rewritten when packets traverse network borders to allow them to continue on to their correct destination. This allows the same IP address to be used on multiple, isolated networks while still allowing these to communicate with each other if configured correctly. A NAT device forwards traffic from the instances in the private subnet to the internet or other AWS services, and then sends the response back to the instances. When traffic goes to the internet, the source IPv4 address is replaced with the NAT device’s address and similarly, when the response traffic goes to those instances, the NAT device translates the address back to those instances’ private IPv4 addresses. NAT devices are not supported for IPv6 traffic—use an egress-only Internet gateway instead.
ARP - The Address Resolution Protocol (ARP) is a communication protocol used for discovering the link layer address, such as a MAC address, associated with a given internet layer address, typically an IPv4 address.
MPLS - (Multi-protocol label switching)
- In conventional internet communication, each router has to make an independent forwarding decision for each packet based solely on the packet’s network-layer header. Thus, every time a packet arrives at a router, it has to rely on its routing logic and this adds latency. Multi-protocol label switching addresses this problem by establishing pre-determined, highly efficient routes. directs data from one node to the next based on short path labels rather than long network addresses, thus avoiding complex lookups in a routing table and speeding traffic flows.
- With MPLS, the first time a packet enters the network, it’s assigned to a specific forwarding equivalence class (FEC), indicated by appending a short bit sequence (the label) to the packet.
- Each router in the network has a table indicating how to handle packets of a specific FEC type. subsequent routers use the label as an index into a table that provides them with a new FEC for that packet.
- Packets carrying real-time traffic, such as voice or video, can easily be mapped to low-latency routes across the network
- MPLS doesn’t fit neatly into the OSI seven-layer hierarchy, and is sometimes classified as Layer 2.5.
- On the negative side, MPLS is a service that must be purchased from a carrier and is far more expensive than sending traffic over the public Internet.