How to Use the Backend for Frontend (BFF) Pattern in Your Mobile Application Architecture

Intellectual Apps’ Founder was recently at the O’Reilly Software Architecture Conference in London, this article is a summary of his presentation.

Maintaining an API gateway these days generally involves handling different types of user facing apps such as a web, mobile (of different platforms) and IOT devices. The Backend for Frontend (BFF) pattern specifically addresses this aspect of software solutions.

The Challenge

At Intellectual Apps we build software solutions, and in creating solutions for our clients we frequently get to build web and mobile apps within a single solution. This often means that we have a single API gateway for all the apps to communicate through. Over numerous clients/projects/products we started to notice a lot of repetition in the modules we built into software solutions, so naturally we sort to find a way we could share functionality across solutions in an easy way and this lead us to start experimenting with microservices.

In building microsevices based solutions, as the name suggests, one ends up having several independent services working together as part of a single solution. This posed a specific challenge for us as we now had to make the user facing apps do a lot more work in composing data from numerous services. So we took a step back and after some brainstorming, we realised that we had several other problems which presented themselves in two forms:

  1. Having all apps communicate through a single API gateway.

    Apps communicating through a single API gateway

  2. Having apps communicate with multiple services.

    Apps communicating directly with microservices

These scenarios created the following specific challenges for us:

Having all apps communicate through a single API gateway.

Given that the data consumption patterns of mobile apps are not the same as web apps, having all the apps share a single API gateway meant that the mobile apps often got more data than necessary when calling the same endpoints being used by the web application. For instance, when returning data to show the details of an item, the web app has room to show way more details than a mobile app can. So when the mobile app calls the same endpoint it simply gets more data that it can possibly display on a small screen which means a lot of the data never gets displayed immediately.

With all apps communicating through a single API gateway, the codebase got bloated. Many attimes this was due to the face that checks were put in place at the API gateway level to determine which app was make the call just so that app specific things could be done.

Having apps communicate with multiple services.

The major challenge with this approach is the extra processing that mobile apps had to do in order compose data coming from multiple independent services in addition to the numerous network calls that have to be made. The immediate effect of this is the drain on battery life.

Enter the BFF

After conducting some research we came across the Backend for Frontend pattern and the motivation for us considering this was to enable us operate in a more agile fashion. The approach was popularized by Sam Newman, the author of Building Microservices. Sam Newman talks about his experience working on a SoundCloud project which faced challenges similar to ours and how he and the team there applied this approach to address the challenges.

We adopted the BFF approach and applied it to our projects and this made our architecture look as follows:

Apps communicating via BFFs

The BFF pattern is a technique where a dedicated layer serves a specific front-end platform. It can easily be seen from the diagram above that each platform gets a specific layer that performs the following functions:

  • Data composition.
  • Some front-end specific logic.

Having BFFs perform the functions listed above means that:

  • Mobile apps won’t have to make multiple network calls.
  • Mobile apps do less work on data as data composition takes place in the BFF.
  • Each platform gets the right data needed from each call.
  • Codebase for each BFF is specific to a platform therefore getting rid of a bloated codebase.

When to use the BFF pattern
If one or more of the following are true in your current architecture then the BFF pattern may be something to consider:

  • You have web, mobile and IOT apps talking to multiple services.
  • You have web, mobile and IOT apps sharing a single API gateway.
  • You are migrating to microservices.
  • You have organisations outside yours consuming your APIs.

A Little More

Typically the front-end team should maintain the BFFs as these layers are technically extensions of the apps they work on. Doing this will let your front-end team iterate faster as they won’t have to communicate with another team, supposing the BFF is maintained by the back-end team.

It may be argued that there will be duplication of code across BFFs, yes, this holds true but the trade-off here is having bloated code in a single API gateway. We even go to the point of having separate BFFs for Android and iOS platforms as this let us focus specifically on one platform.

It also goes without saying that with the BFF approach, there will be more codebases to maintain.

That’s it and I hope you find this article useful, and consider using this pattern as we do at Intellectual Apps so you could respond faster to client and user requirements.

Posted by Bulama Yusuf

Getting a Mobile App Will Keep You in Business, Here’s Why

It’s obvious. Fifteen years ago the saying was that if you don’t have your business online, you’re out of business. Businesses did all they could to make sure that they had presence online by having a company website. It’s obvious that the business climate has changed and today if your business is not connecting with customers via mobile then you are out of business or somewhere close to that.

To better understand this, we’ll continue by answering the following questions:
1. Why does your business need to go mobile?
2. What does going mobile mean for your business?
3. What steps can you take to get your business mobile?

Why does your business need to go mobile?

Simple answer: we are now deep into the post-pc era. Longer answer: well, your customers expect it and studies have shown how much time people spend on their devices doing virtually everything. One of the ways businesses ensure that they remain in business is by staying fresh in the minds of their existing customers and by being visible to potential customers. So when people do everything from their mobile devices it makes sense to have your business present in this new virtual world. Another reason why your business needs to go mobile is that you will get to generate and analyse lots of data and in turn use that for more informed business decisions that will ultimately give you an edge over the competition, but most importantly let you offer customers a better experience.

If you sell a product, imagine what this will mean for your business to be able to tell on which days you get the most sales and from which demographic the sales come from, and also being able to know if there are specific things outside of your business that trigger a spike in sales of a particular item so you can prepare for such scenarios. All these are just examples and more meaningful insights can be derived for your specific line of business.

What does going mobile mean for your business?

It means positioning your business in such a way that it responds to your customer’s mobile behaviour. The way people consume information on mobile devices is slightly different from how they do it with other sources of information. People are on the go, they want things fast, they have a short attention span and need the right information at the right time. For example, if all your business has online is a website, then that website needs to render correctly and fast on mobile devices.

What steps can you take to get your business mobile?

What your business needs in order to go mobile would depend on the type of business you have and what you want to achieve with your mobile strategy. Some steps you can take are:

1. Ensuring that your current website is responsive. What responsive simply means is the ability of your website to render and display well on different screen sizes.

2. Ensure as part of your mobile strategy to build and release new features with a mobile-first approach.

3. To take things further and in solidifying the interaction between your business and your customers, you can get a mobile app built to meet your specific requirements. If you seek a deeper and richer engagement with your customers then having a mobile app built for your business is the way to go.

4. Another thing you need to consider in going mobile is that it isn’t all about building this or building that, going mobile also has a lot to do with how you disseminate information to your audience. The information you put out there will be more useful to your customers if you consider the context within which they are most likely to consume that piece of information (stay tuned for a post giving more details on this).

5. If you are really serious about this, which we believe every business owner or stakeholder should be, then you can get a competent company to help you come up with a mobile strategy and chart a way to get your business from where it is today to where you need to be. You can start by talking to us.

Posted by Bulama Yusuf