Previously I was blogging about the BFF dilemma. I want to continue to explore the subject because I find it very interesting and I believe they’re still a lot of things to explore on the subject. BFFs are super popular nowadays, for several reasons, mainly I would because of the nature of modern products. If you have a digital product is very likely you will need to ship your problem in at Least 3 platforms (Web, Ios, Android) somethings even more platforms and specialized devices like TVs, Tablets, IoT, Arduinos and much more. Also, microservices were a big force pushing for BFFs since the services are “micro” and code need to live somewhere. It’s really interesting when we think about them since we have so many options and places where our code can live.
Latency, Unstable networks and Tradeoffs
Latency is a real issue. If you don’t pay attention to Latency for mobile apps means losing money. Apps need to perform as fast as they can to improve user experience and do not affect business transactions. Mobile carriers often have unreliable and unstable networks which require all sorts of smart architecture at the mobile side such as:
* Bootstrap cache: When the app loads it’s a good time to HIt the cache.
* On-Demand cache: Background threads can load and cache data with the battery cost and app size as a tradeoff(Latency vs Complexity).
* Offline management: As the network fails for Mobile network carrier issue or because there is an outage on the backend being able to retry in a smart fashion and sync state on demand is complex but yet a powerful feature. Techniques like Exponential backoff + Jitter with conjunction with CRDTs can be super useful but at the same time complex.
* What if the data keeps changing? Could you optimize the network calls somehow? Could you change the application workflow to be more push driven rater than pull driven?
All these problems can get very tricky and very complex at scale. BFFs can help you there since you can aggregate several backend calls in just one shot.
It’s all about Aggregation
So at the end of the day, BFFs are about aggregation. Having a place where you can code stuff allows you to reduce the number of calls and have smarter chances in order to reduce latency and improve user experience. BFFs not necessarily means you need to write them in nodejs. You could build BFFs in any language like Java, Go, or RUST. I would argue that Rust is a super interesting language in a sense of performance and low latency. Also, there is a movement that grows a lot called “Edge Computing” more and more we can run code in POPs(Points of presence). Where you can run code close to your user and reduce the latency and make things more simple. The issue is if you dont have POPs available for you.
So if you have your frontend in Java(Most companies have in React or Angular). Makes sense to have the BFF written in NodeJS for sake of commodity and the frontend team should maintain that piece of software. However, since this post is about dilemmas :-) What happens to IoS and Android consumers? So we will write the BFF in Java? What about Ios? So clearly one trade-off could be using a different language or provide an efficient engine that could something like GraphQL(If you implement well) or Some centralized middleware(I’m not talking about ESB for God Sake :-) ). To some degree, BFFs are distributed aggregation(like services or microservices).
BFFs(when code based) provide the ultimate flexibility and freedom to pick the best strategies and combine techniques for different use cases. I would argue that a Web app with Microfrontends for instance and Mobile-First Apps are very different problems although both could be using BFFs.
In defense of Drivers and Clients
One interesting thing you can so(considering SOA and Services) is to have a client or driver. Drivers make service consumption more native and more productive for consumers. Having a driver/client allows the services to provide backward compatibility to the client as well. Also, you need to see that when you have a client/driver you have type safety and this is a killer feature.
You can combine BFFs with clients/drivers although there are some overlaps. Since you have more than one place to Cache things, to provide backward compatibility, to do validations. So you need to be careful to not fall into some traps like:
* Coupling the driver/client with the BFFs
* Have lots of delegation layers that dont add value and just add latency and complexity.
Back to the BFF Dilemma
IMHO BFF is a very wide pattern and can be used for several different use cases such as:
* Mobile First Apps
* Microfront ends — Web Apps
* General aggregation for any “consumer” — IoT, Arduino, TVs, etc…
When you stop to think about different use cases you might realize overlap with other technologies like GraphQL, API Gateways, Service Meshes, Sidecars, Services/Microservices. Like I said, in the beginning, there are lots of places we can “add code” we need carefully consider the use cases and tradeoffs.
Originally published at http://diego-pacheco.blogspot.com on August 28, 2020.