This week’s system design refresher:
Twitter Structure 2022
What’s Single Signal-On? (Youtube video)
Code First v.s. API First
The Ping command
API architectural kinds
Be part of ByteByteGo Expertise Collective
The diagram beneath reveals how information is encapsulated and de-encapsulated when transmitting over the community.
Step 1: When System A sends information to System B over the community through the HTTP protocol, it’s first added an HTTP header on the software layer.
Step 2: Then a TCP or a UDP header is added to the info. It’s encapsulated into TCP segments on the transport layer. The header incorporates the supply port, vacation spot port, and sequence quantity.
Step 3: The segments are then encapsulated with an IP header on the community layer. The IP header incorporates the supply/vacation spot IP addresses.
Step 4: The IP datagram is added a MAC header on the information hyperlink layer, with supply/vacation spot MAC addresses.
Step 5: The encapsulated frames are despatched to the bodily layer and despatched over the community in binary bits.
Steps 6-10: When System B receives the bits from the community, it performs the de-encapsulation course of, which is a reverse processing of the encapsulation course of. The headers are eliminated layer by layer, and ultimately, System B can learn the info.
We want layers within the community mannequin as a result of every layer focuses by itself tasks. Every layer can depend on the headers for processing directions and doesn’t have to know the that means of the info from the final layer.
The diagram beneath reveals the variations between code-first growth and API-first growth. Why can we need to think about API first design?
Microservices improve system complexity.
We have now separate providers to serve completely different features of the system. Whereas this sort of structure facilitates decoupling and segregation of obligation, we have to deal with the assorted communications amongst providers.
It’s higher to suppose by means of the system’s complexity earlier than writing the code and thoroughly defining the boundaries of the providers.
Separate practical groups want to talk the identical language.
The devoted practical groups are solely accountable for their very own parts and providers. It is suggested that the group communicate the identical language through API design.
We will mock requests and responses to validate the API design earlier than writing code.
Enhance software program high quality and developer productiveness
Since we now have ironed out a lot of the uncertainties when the venture begins, the general growth course of is smoother, and the software program high quality is enormously improved.
Builders are joyful in regards to the course of as nicely as a result of they will deal with practical growth as a substitute of negotiating sudden adjustments.
The opportunity of having surprises towards the tip of the venture lifecycle is lowered.
As a result of we now have designed the API first, the exams will be designed whereas the code is being developed. In a means, we even have TDD (Take a look at Pushed Design) when utilizing API first growth.
The diagram beneath reveals how the “ping” command works.
The “ping” command runs on ICMP (Web Management Message Protocol), which is a community layer protocol.
There are 6 frequent forms of messages in ICMP. For the ping command, we primarily use “echo request” and “echo reply”.
Host A sends an ICMP echo request (kind = 8) with a sequence number one. The request is encapsulated with an IP header to specify the supply and vacation spot IP addresses.
When host B receives the info, it sends again an ICMP echo reply (kind = 0) with sequence number one to host A.
When host A receives the echo reply, it correlates the request and reply with the sequence quantity, and makes use of T1 and T2 to calculate the spherical journey time. That’s how we see the ping statistics.
Since RPC has change into a scorching subject, let’s briefly assessment its historical past.
The diagram beneath illustrates the API timeline and API fashion comparability.
Over time, completely different API kinds are launched. Every of them has its personal patterns of standardizing information change.
For those who’re hiring, be a part of ByteByteGo Collective to begin getting weekly drops of world-class hand-curated engineers who’re open to new alternatives.
For those who’re on the lookout for a brand new job, be a part of to get personalised alternatives from hand-selected firms. You possibly can be a part of publicly or anonymously, and go away anytime.
Openedges: Chief Architect (San Jose, Austin, Distant)