Skip to content

Commit 9d9cd8c

Browse files
committed
Add Remote procedural call (RPC) section
1 parent 9a3a2c4 commit 9d9cd8c

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,3 +1525,52 @@ Use UDP over TCP when:
15251525
* [Transmission control protocol](https://en.wikipedia.org/wiki/Transmission_Control_Protocol)
15261526
* [User datagram protocol](https://en.wikipedia.org/wiki/User_Datagram_Protocol)
15271527
* [Scaling memcache at Facebook](http://www.cs.bu.edu/~jappavoo/jappavoo.github.com/451/papers/memcache-fb.pdf)
1528+
1529+
### Remote procedural call (RPC)
1530+
1531+
<p align="center">
1532+
<img src="http://i.imgur.com/iF4Mkb5.png">
1533+
<br/>
1534+
<i><a href=http://www.puncsky.com/blog/2016/02/14/crack-the-system-design-interview/>Source: Crack the system design interview</a></i>
1535+
</p>
1536+
1537+
In an RPC, a client causes a procedure to execute on a different address space, usually a remote server. 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. Remote calls are usually slower and less reliable than local calls so it is helpful to distinguish RPC calls from local calls. Popular RPC frameworks include [Protobuf](https://developers.google.com/protocol-buffers/), [Thrift](https://thrift.apache.org/), and [Avro](https://avro.apache.org/docs/current/).
1538+
1539+
RPC is a request-response protocol:
1540+
1541+
* **Client program** - Calls the client stub procedure. The parameters are pushed onto the stack like a local procedure call.
1542+
* **Client stub procedure** - Marshals (packs) procedure id and arguments into a request message.
1543+
* **Client communication module** - OS sends the message from the client to the server.
1544+
* **Server communication module** - OS passes the incoming packets to the server stub procedure.
1545+
* **Server stub procedure** - Unmarshalls the results, calls the server procedure matching the procedure id and passes the given arguments.
1546+
* The server response repeats the steps above in reverse order.
1547+
1548+
Sample RPC calls:
1549+
1550+
```
1551+
GET /someoperation?data=anId
1552+
1553+
POST /anotheroperation
1554+
{
1555+
"data":"anId";
1556+
"anotherdata": "another value"
1557+
}
1558+
```
1559+
1560+
RPC is focused on exposing behaviors. RPCs are often used for performance reasons with internal communications, as you can hand-craft native calls to better fit your use cases.
1561+
1562+
Choose a Native Library aka SDK when:
1563+
1564+
* You know your target platform.
1565+
* You want to control how your "logic" is accessed
1566+
* You want to control how error control happens off your library
1567+
* Performance and end user experience is your primary concern
1568+
1569+
HTTP APIs following **REST** tend to be used more often for public APIs.
1570+
1571+
#### Disadvantage(s): RPC
1572+
1573+
* RPC clients become tightly coupled to the service implementation.
1574+
* A new API must be definied for every new operation or use case.
1575+
* It can be difficult to debug RPC.
1576+
* You might not be able to leverage existing technologies out of the box. For example, it might require additional effort to ensure [RPC calls are properly cached](http://etherealbits.com/2012/12/debunking-the-myths-of-rpc-rest/) on caching servers such as [Squid](http://www.squid-cache.org/).

0 commit comments

Comments
 (0)