|
| 1 | +# Internet Protocol Suite |
| 2 | + |
| 3 | +When talking about network communications, the first thing you need to understand is the `Open Systems Interconnection Model (OSI Model)` |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +For the system design purpose, we don't need to go lower than layer 4. |
| 8 | + |
| 9 | +The most commonly used protocols are summarized in this table: |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +It is definitely not a complete table, and we are particularly interested in the following areas: |
| 14 | + |
| 15 | +- TCP vs UDP: |
| 16 | + - TCP: |
| 17 | + - connection-oriented protocol |
| 18 | + - connection established between the peer entities prior to transmission |
| 19 | + - transmission flow is controlled such that a fast sender does not overwhelm a slow receiver. |
| 20 | + - UDP: |
| 21 | + - message-oriented protocol |
| 22 | + - basically broadcasting messages, no connection/sequence guaranteed |
| 23 | + |
| 24 | +- Other transport layer protocols: |
| 25 | + - QUIC: Based on UDP, initially designed by google. |
| 26 | + - SCTP: Combination of TCP and UDP, used for telephony over the Internet. |
| 27 | + |
| 28 | +- TCP/IP: |
| 29 | + - Sometimes people also talking about TCP/IP, it means a protocol stack which contains different protocols required for the data transfer from sender to receiver |
| 30 | + - Details can be seen [here](https://stackoverflow.com/questions/31473578/tcp-ip-and-tcp-and-ip-difference) and [here](https://www.fortinet.com/resources/cyberglossary/tcp-ip) |
| 31 | + |
| 32 | +- HTTP: How does it work when a client wants to communicate with a server |
| 33 | + - Open a TCP connection |
| 34 | + - Send an HTTP message |
| 35 | + - Read the response sent by the server |
| 36 | + - Close connection (or reuse connection for further communication) |
| 37 | + |
| 38 | +- HTTPS: |
| 39 | + - Extension of HTTP, but more secure |
| 40 | + - Use SSL/TLS to ensure security of data transportation |
| 41 | + |
| 42 | +- socket: |
| 43 | + - A socket is one endpoint of a two-way communication link between two programs running on the network. |
| 44 | + - A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent to. |
| 45 | + |
| 46 | +- websocket: |
| 47 | + - A WebSocket is a persistent connection between a client and server |
| 48 | + - WebSockets provide a bidirectional, full-duplex communications channel that operates over HTTP through a single TCP/IP socket connection |
| 49 | + |
| 50 | +- HTTP vs Long-polling vs websocket: |
| 51 | + - HTTP is a strictly unidirectional protocol |
| 52 | + - Long-polling is an HTTP request with a long timeout period |
| 53 | + - resources on the server are tied up throughout the length of the long-poll, even when no data is available to send. |
| 54 | + - Websocket: allow for sending message-based data, similar to UDP, but with TCP |
| 55 | + - uses HTTP as the initial transport mechanism (i.e. HTTP request headers), but keeps the TCP connection alive after the HTTP response is received |
| 56 | + - Once TCP connection is established, it uses websocket protocol to communicate |
| 57 | + - WebSocket is a framed protocol, meaning that a chunk of data (a message) is divided into a number of discrete chunks, with the size of the chunk encoded in the frame. |
| 58 | + - The frame includes a frame type, a payload length, and a data portion. |
| 59 | + - More comparison between websocket and http can be seen [here](https://www.geeksforgeeks.org/what-is-web-socket-and-how-it-is-different-from-the-http/) |
| 60 | + |
| 61 | +- REST: |
| 62 | + - a software architectural style that was created to guide the design and development of the architecture for the World Wide Web |
| 63 | + - Any web service that obeys the REST constraints is informally described as **RESTful** |
| 64 | + - The goal of REST is to increase performance, scalability, simplicity, modifiability, visibility, portability, and reliability. |
| 65 | + - Six guiding constraints define a RESTful system: |
| 66 | + - Client–server architecture |
| 67 | + - client application and server application MUST be able to evolve separately without any dependency on each other |
| 68 | + - Statelessness |
| 69 | + - The server will not store anything about the latest HTTP request the client made. It will treat every request as new. No session, no history. |
| 70 | + - Cacheability |
| 71 | + - caching shall be applied to resources when applicable |
| 72 | + - Caching can be implemented on the server or client-side. |
| 73 | + - Layered system |
| 74 | + - allows you to use a layered system architecture where you deploy the APIs on server A, and store data on server B and authenticate requests in Server C |
| 75 | + - Uniform interface |
| 76 | + - A resource in the system should have only one logical URI, and that should provide a way to fetch related or additional data. |
| 77 | + - Code on demand (optional) |
| 78 | + - you are free to return executable code to support a part of your application |
| 79 | + |
| 80 | +- REST vs SOAP |
| 81 | + - REST is an architectural style, while SOAP is a protocol |
| 82 | + - REST is not a standard in itself, but RESTful implementations make use of standards |
| 83 | + |
| 84 | +- HTTP response status codes |
| 85 | + - For a full list please see [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) |
| 86 | + - Some common ones: |
| 87 | + - 200: ok/success |
| 88 | + - 201: created |
| 89 | + - 202: accepted |
| 90 | + - 204: No content |
| 91 | + - 300: more than one possible response |
| 92 | + - 301: permanent redirect |
| 93 | + - 302: temporarily redirect |
| 94 | + - 400: The server could not understand the request due to invalid syntax. |
| 95 | + - 401: unauthenticated |
| 96 | + - 403: Permission denied |
| 97 | + - 404: The server can not find the requested resource (URL not recognized) |
| 98 | + - 500: Unhandled error on server |
| 99 | + - 502: Server got an invalid response |
| 100 | + |
| 101 | + |
| 102 | +Reference: |
| 103 | + |
| 104 | +- [Network Layers & Network Layer in OSI Model](https://www.router-switch.com/faq/network-layers-in-osi-model-features-of-osi.html) |
| 105 | +- [Application Layer (Internet protocol Suite) ~ Networking Space](http://walkwidnetwork.blogspot.com/2013/04/application-layer-internet-protocol.html) |
| 106 | +- [The Internet protocol suite (article) \| Khan Academy](https://www.khanacademy.org/computing/computers-and-internet/xcae6f4a7ff015e7d:the-internet/xcae6f4a7ff015e7d:the-internet-protocol-suite/a/the-internet-protocols) |
| 107 | +- [QUIC - Wikipedia](https://en.wikipedia.org/wiki/QUIC) |
| 108 | +- [An overview of HTTP - HTTP \| MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview) |
| 109 | +- [What Is a Socket? (The Java™ Tutorials > Custom Networking > All About Sockets)](https://docs.oracle.com/javase/tutorial/networking/sockets/definition.html) |
| 110 | +- [WebSockets - A Conceptual Deep Dive \| Ably Realtime](https://ably.com/topic/websockets) |
| 111 | +- [How Do Websockets Work? - Kevin Sookocheff](https://sookocheff.com/post/networking/how-do-websockets-work/) |
| 112 | +- [Representational state transfer - Wikipedia](https://en.wikipedia.org/wiki/Representational_state_transfer) |
| 113 | +- [REST Principles and Architectural Constraints](https://restfulapi.net/rest-architectural-constraints/) |
0 commit comments