IPC for Dev
What is IPC
IPC (inter process communication) is a way for disparate processes to share data and requests. There are a lot of ways to implement them, since we are focused on the distributed computing communication for apps, we will focus on IPC methods that spans systems.
Lets quickly go over some IPC methods.
Now looking at the above list, the most interesting for a developer is “Message Passing” OR RPC where examples include gRPC, RPC, CORBA and Java RMI.
Why do we need more efficient RPC
RPC is a special IPC where the resource is not local (or same machine)As we march towards FaaS (Function as a Service) the chatter between the service goes up exponentially. As you can see from the following example, one get call to get user attributes triggers multiple downstream calls. This is great for developer productivity and rolling out features faster but can impact the performance of the application due to multiple hops. This is where efficient IPC plays a critical role.
Design Considerations
We will later look into a few options available for distributed system IPC, lets go over the design considerations and constraints
Constraints
- size of the payload
- Latency incurred
- # of requests (chattiness)
- complexity
Once we have all the above data point we can decide wether to go RPC or REST route.
RPC v/s REST
Lets use node
to showcase the difference between 2 approaches
RPC
var Product_ID = 1;var PRODUCTS = [
{ id: Product_ID, name: 'iphone', manufacturer: 'Apple' }
];var app = http.createServer(function onRequest(req, res) {
if (req.url === '/getProductById?id=' + Product_ID) {var product = PRODUCTS.find(function findProduct(p) {
return p.id === Product_ID;
});res.setHeader('Content-Type', 'application/json; charset=utf-8');res.end('{' + '"name":"' + product.name + '"}');
}
});
Response
curl http://localhost:9999/getProductById?id=1
{"name":"iphone"}
REST
var Product_ID = 1;var PRODUCTS = [
{ id: Product_ID, name: 'iphone', manufacturer: 'Apple' }
];var app = http.createServer(function onRequest(req, res) {
if (req.method === 'GET' &&
req.url === '/product/phones/' + Product_ID) {var product = PRODUCTS.find(function findProduct(p) {
return p.id === Product_ID;
});res.setHeader('Content-Type', 'application/json; charset=utf-8');res.end('{"id":' + product.id + ',"name":"' + product.name +
'","manufacturer":"' + product.manufacturer + '"}');
}
});
Response
curl http://localhost:9999/product/phones/1
{"id":1,"name":"iphone","manufacturer":"iphone"}
From the above examples you can see the following:
Remote Procedure Call (RPC) lets you invoke remote procedures by passing messages. Implemented by generating stubs ( client and server side) that will take care of marshalling/unmarshalling the request. It is typically over TCP and focuses on commands and has lot fewer objects.
Representational State Transfer (REST) is focused on resources. Client specifies the resources and server shares the state of the requested resources. Heavily relies on HTTP and hence actions are defined by the http verbs.