Learning to love GRPC

Luiz Parreira
Bipa Engineering
Published in
3 min readApr 3, 2021
Photo by Scott Fletcher on Unsplash

At Bipa, we have integrated into the Lightning Network in order to provide our users with a cheap way to transfer their Bitcoins into their own custody. At first, I took this challenge as an experiment, I didn’t know how users and the market were going to react. When integrating Lightning into our server, I had to decide whether I would be using the GRPC or the REST client. After doing some research around clients that were available for me to use, I stumbled upon the lnd-rust package, which hasn’t been updated in 2 years. That’s not the kind of package we want to add to our server running in production, right? It became clear I would have to write my own client as nothing else was available for lnd.

In order to simplify, I went with the REST client. I quickly wrote an internal client that would interface with lnd’s REST API. It worked great until we figured that we also wanted to use some of LND’s new APIs, which rely on streaming a response to you rather than the standard HTTPS request/response workflow. We found that the lnd endpoints that we wanted to use would not work with the client we had built.

In addition to that, I realized that the REST client is just a wrapper around the GRPC server that lnd has implemented internally, which meant that for every request that we made, there were two networking trips occurring, one between our server and LND’s REST server, and one between LND’s REST server to the GRPC server. (I may be wrong about this though, please correct me if I am).

I said earlier that integrating Lightning into Bipa was supposed to be an experiment. It was an experiment that really worked for us, Lightning fits really well into how Bipa works and our mission. As soon as we launched Lightning support, everything changed. Users started actually using Bipa and the experiment quickly evolved into: we need to really support this and get to a place where we are actively contributing to its success and evolution.

Our first attempt at contributing back to the community, and also improving our users’ experience is lnd-rs , which is a GRPC client that allows any Rust developer to easily connect to LND. Right now, the library is in its infancy and only implements functions that we use, but over the coming weeks and months, we will implement all missing functions and create comprehensive documentation that other developers can use to integrate lnd into their Rust application. Let us know if you need anything that we have not yet implemented. Also, anyone is free to contribute.

Using GRPC has improved the performance of one of our major workflows by 3x, one request that used to take 3 secs, now takes 1sec to complete. At the moment, Bipa is just a small company with a couple of developers, but we have already gotten a taste of how amazing GRPC can be. We plan to start experimenting with it by migrating our pricing server, and when we have to scale to hundreds of developers, we will certainly use it for our main server.

If you love Bitcoin, Lightning, Rust, GRPC, or just coding in general, and would like to work with us. DM me on Twitter or Linkedin.

--

--