How to build a scalable mobile app infrastructure?

How to build a scalable mobile app infrastructure?
Mobile App Infrastructure

Are you looking to scale a mobile app infrastructure? Here is an in-depth tutorial detailing real-life lessons of how to scale mobile application infrastructure.

What is a mobile app?

A mobile app is an application that runs on a mobile device like smartphones, tablets, and watches. There are multiple types of mobile apps, including native apps, hybrid apps, and web apps.

  • Native apps work for a specific operating system like Android or iOS;
  • Web apps are coded using technologies like HTML5 and CSS;
  • Hybrid apps work like web apps but are framed within a native container.

Keep reading to learn more about a mobile app infrastructure architecture.

Web apps vs Hybrid Apps vs Native Apps

What is the definition of a scalable app architecture?

Building mobile apps at scale is not easy, and many variables are essential when defining a scalable architecture.

A large and scalable mobile application will most likely support thousands or even million uses and need to be performative, reliable, and secure.

It means that a best-in-class architecture will have no downtimes, no crashes, fast loading speeds, and state-of-the-art security.

This article will consider these factors to propose a scalable backend infrastructure for mobile apps.

How does a mobile app infrastructure looks like?

Several elements compose a mobile application architecture and below is the infrastructure needed for mobile apps.

  • App publishing platforms
  • SDKs – Software Development Kits
  • APIs
  • CDN – Content Delivery Network
  • Object Storage
  • Load Balancers
  • Application Servers
  • Database Servers

Keep reading to learn more about a scalable mobile app architecture and each of the layers described above.

Mobile App Architecture

App publishing platforms

It’s possible to build a mobile application using different technologies. From native iOS and Android development languages like Swift and Kotlin/Java to cross-platform development frameworks like React Native or Flutter.

The technologies described above will create the frontend of a mobile application or the client-side interface. Application stores like Google Play and App Store provide the ecosystem to distribute mobile applications to the end-users.

Developers need to submit their mobile apps to these publishing platforms, wait for their review, and only after accomplishing this step will they be able to have the app up and running.

Both Google Play and App Store have different publishing guidelines, and it’s essential to read them first to avoid issues that could prevent publishing an app.

To avoid going through the scrutiny of the application stores, an alternative is developing a PWA – Progressive Web Applications using technologies like React, Angular, and Ionic.

SDKs – Software Development Kits

Software Development Kits are a essential step in building a scalable mobile app infrastructure. An SDK consists of an installable package with tools like APIs, libraries, debugger, documentation, etc.

A mobile backend SDK will most likely include elements that bridge the interface between the backend and the frontend.

An easy-to-understand example is sending a push notification from the backend to the frontend. An SDK will facilitate this action and accelerate the integration of the functional elements.

APIs – Application Programming Interfaces

APIs are a vital element in developing a mobile app architecture. APIs are software interfaces that connect the frontend (client-side) to a mobile application’s backend (server-side).

The advantages of using API in a mobile app backend implementation include automating tasks, customizing functions, flexible delivery of information, and distributing new services.

API - Mobile App Infrastructure

CDN – Content Delivery Network

A CDN is a geographically distributed group of servers that work together to supply fast content delivery. These servers are located closer to the end-users and will allow a faster transfer of assets to load internet content (images, videos, etc.).

Additional advantages of CDN implementation include reducing communication time between a mobile app client-side to the server-side via optimal routing, reducing bandwidth costs, and security (DDoS attacks, certificates, etc.)

Object Storage

This element of the mobile app infrastructure will connect to the CDN and encompass file storage, video storage, images storage, etc. The CDN will cache the content and accelerate delivery time to the location nearest to the end-user.

Load Balancers

The next layer in creating a mobile app infrastructure is the load balancers. In cloud computing, load balancers distribute tasks over a set of servers to make their overall processing more efficient.

The CDN will connect to the load balancers, and the load balancer software will distribute client-side requests efficiently, ensure high availability, and scale up/down depending on the demand.

Application Servers

The next step in building a mobile application architecture is the application servers. This piece of the infrastructure will handle the business logic, and they stay in the middle between the database servers and the CDN.

Database Servers

The final step in setting up a mobile application infrastructure is creating the database servers. A database cluster comprises high-powered instances that store and manipulates data stored.

A database infrastructure can be redundant or not. Redundant architectures will provide at least two instances synchronizing data in real-time.

How to scale a mobile application?

There are mainly two ways to build a scalable application infrastructure. The first one is using managed services like a Mobile Backend as a Service, and the second way is making the backend from scratch using an Infrastructure as a Service provider.

Using a BaaS service includes a ready-to-use and scalable infrastructure, out-of-the-box building blocks to accelerate backend development, and SDKs to streamline server-side and client-side integration. In general, app scaling is easier to achieve using a backend platform.

Developing a backend from scratch will provide developers with more flexibility and control over most infrastructure elements. On the other hand, they will need to manage the backend and scale up and down the infrastructure depending on the workload.

Let’s explore in more detail each of these two options.

BaaS – Backend as a Service

Scaling a mobile application backend using a BaaS is extremely easy, and all elements are in place to achieve this goal. The core business of a BaaS platform is delivering a hassle-free, secure, and scalable architecture to its clients.

Some backend providers like Back4App will allow users to create a backend in just a few minutes. The first step is to Sign Up and name the first app.

Scalable backend - Back4app Login

The next step is fully automated, and the platform will deliver a data model, application servers, scaling policies, backups, and security in just a few minutes.

Scalable backend - Back4app creating app

The next screen provides a GUI – Graphical User Interface encompassing the data model, serverless functions, APIs, and infrastructure settings.

Scalable backend - Back4app dashboard

The backend is ready-to-use, has built-in scalability, and all the user has to do is connect the application frontend to the backend via SDKs, upload data, and code the business logic.

Back4App offers many ready-to-use SDKs, including React Native, Flutter, Android, iOS, Javascript, Xamarin, etc.

Scalable backend - Back4app SDKs

To know in more granular details how to build your first application using Back4App, please refer to the tutorial Create Your First App With Back4App.

Real-life examples of scaling a mobile app infrastructure

Below are two practical examples of the advantages of using a Backend as a Service to scale a mobile app infrastructure.

  • Broadcast

The first example we will use is the Norwegian startup Broadcast Oslo. The company is a free guide for festivals, concerts, and clubs in Oslo.

Broadcastoslo is a mobile first application and distribute their app on both Google Play and App Store. Users download and have access to all future events that will happen in Oslo on the upcoming months.

The application also allows users to access festival schedules in real-time, and that is where the infrastructure scalability challenges start.

The Musikkfest Oslo 2022 happened on June 4th and had approximately 20 thousand participants. So, imagine how scalable infrastructure has to be to support thousands of users accessing and retrieving data from an app concurrently. 

Broadcast’s technical team decided to use Back4App to solve this problem, and the results were excellent! Here is what Tim Harris, Broadcast’s CEO, said about the experience.

Thanks again for all your help, it’s been a very successful day for us, and so important that we didn’t have any problems with people accessing the app!

Tim Harris, Broadcast’s CEO
  • Fight List

Fight List has more than 10M downloads, and it’s a very successful game created by Two4Tea. It is a questions and answers game, distributed in more than seven languages, and reached top rankings in the US and France. 

The game has sophisticated scaling challenges and requires thousands of users to access the app simultaneously.

Two4Tea chose Back4app to solve the infrastructure challenge and processed more than 10k requests/second on peak usage. Here is what Nicolas Boulch, Two4Tea’s CEO, said about the experience.

At this time we realized that Back4App was the right choice because they could analyze our app specifically and build a custom solution to us

Nicolas Boulch, Two4Tea’s CEO

To more about Fight List’s scaling challenges, please read the article Scaling a Game With Back4App.

Build a custom backend on any major cloud provider

The second option to build a scalable mobile application infrastructure is building the backend using cloud providers like AWS, Google Cloud, Azure, Digital Ocean, etc.

The advantages of going for this setup rely primarily on the flexibility it will provide, more control over the backend infrastructure, and visibility over each process step.

The downsides rely on the engineering efforts to build and maintain the backend infrastructure, develop boiler-plate backend code, and monitor the systems around the clock.

AWS is the most used cloud provider worldwide. Let’s use this vendor to illustrate the steps to create a scalable mobile application backend.

The first step is to create and active an account with AWS. Please follow the tutorial How do I create and activate a new AWS account for further details on how to proceed.

The next step is defining the products that will support the backend implementation. We will use the following on this example:

  • EC2 Instances
  • EBS – Elastic Block Storage
  • S3 – Simple Storage System
  • Load Balancers
  • CDN – CloudFront

Let’s explore in further details each step.

Creating EC2 Instances

A scalable backend infrastructure will require application and database virtual machines. The first step is to define the instance model to use on the cluster.

AWS offers multiple instance types that are optimized for many use cases. The list encompasses general purpose, compute optimized, memory-optimized, accelerated computing, and storage optimized instances.

For this example, we will use a general-purpose instance. Let’s start with a t4g.medium instance that provides an Arm-based architecture; it’s excellent for burstable workloads and offers a great price per hour.

Below are the initial steps to follow:

  • Login to AWS
Scale Mobile App Infrastructure - Login AWS
  • Go to EC2
  • Instances
Scalable backend - Create instance
  • Launch a New Instance
Scalable backend - Launch an instance

This step must define the operating system, the instance type, and size, network settings, add block storage to the instance, security settings, etc.

For further information on setting up an EC2 instance, please follow the tutorial Create and launch an EC2 instance

As soon as the server cluster is ready, the next step is to configure the scaling policies based on the workload.

There are two ways to scale a server cluster: horizontal scaling and vertical scaling.

  • Horizontal Scaling – adding more instances to the cluster to cope with new workloads.
  • Vertical Scaling – adding more resources (CPU/RAM) to an instance to meet the new workload, i.e., increasing the size of the instance.

Generally speaking, application servers will use horizontal scaling as a preferred scaling mechanism. A database cluster will use vertical scaling as a preferring scaling method.

Horizontal scaling an application cluster is, in general, a simple process. The way to do it using AWS is by accessing the Auto Scaling menu and launching a new configuration.

Vertical database scaling is a more complex process because it’s impossible to shut down the instance and change the instance size. This way, the cluster would face downtime.

The right way is to create a new larger instance, synchronize the data, and transfer workload processing to the larger instance. There is no rocket science in doing that, but automating this process is time-consuming.

If the application workload grows so much that the vertical database scaling is no longer possible, distributing the workload in multiple instances will be the only path forward. It is a complicated implementation and should be used only as a last option.

For detailed steps on how to add auto scaling to EC2, please follow the tutorial Get started with Amazon EC2 auto scaling.

EBS – Elastic Block Storage

Each instance will require an attached EBS volume. The exception is ephemeral instances with the storage built into the hardware.

It is an easy step done during the initial virtual machine configuration. The challenge is to determine the correct EBS size to avoid unnecessary costs and adequate capacity to store data.

Choosing the correct EBS type is also essential. There are many EBS options, including SSD and Magnetic disks. Selecting the adequate EBS type is vital to guarantee a good balance in performance and costs.

For further information on how to attach an EBS volume to a virtual machine, please refer to Attach an Amazon EBS volume to an instance.

S3 – Simple Storage Service

A robust and scalable backend infrastructure will require object storage. Doing that with AWS is an easy task, and S3 is the ideal product to achieve this goal.

The first step in creating an S3 bucket is defining the region to store the files. Generally speaking, you shall choose the same region as the EC2 instance.

Scalable mobile app infrastructure - Build S3 bucket.

As part of the creating process, defining the object ownership, public access rules, bucket versioning, and encryption requirements are necessary.

AWS S3 buckets are scalable by default, and users will only pay for the resources used. For additional information on creating an S3 bucket, please follow the tutorial Creating an S3 bucket.

Load Balancers

A scalable infrastructure requires a correct load balancer implementation. AWS offers several load balancer types as part of their products.

The application load balancers will route the requests to the correct EC2 instances and monitor these instances’ health.

Attaching load balancer to instances is not a complex process and cover the following steps:

  • Go to the EC2 dashboard
  • Load Balancing
  • Creat Load Balancer
  • Select Load Balancer Type
Scaling a mobile app infrastructure - Load Balancer Type.
  • Configure the Load Balancer regarding to IP address type, VPCs, availability zones, and add on services.

For detailed information on how to set up a load balancer, please refer to the tutorial Getting started with application load balancers.

Cloudfront CDN

Cloudfront is a built-in content delivery network available at AWS that supports around 300 edge locations worldwide. The product accelerates static and dynamic content distribution, increases security, and is easy to integrate with other AWS products.

As part of a scalable backend architecture, Cloudfront will connect with the S3 buckets and with the load balancers.

Users can connect Cloudfront to the load balancers via the EC2 dashboard, creating a load balancer, targeting groups, and configuring a Cloudfront distribution. More details are available at Setting up a Cloudfront distribution for EC2.

Connecting Cloudfront to an S3 bucket is also straightforward. The connection happens via the Cloudfront dashboard, creating a Cloudfront distribution and adding the origin domain. You can read the blog post Creating AWS CloudFront Distribution with S3 Origin for further information.

Conclusion

A mobile application works on devices like cellphones, tablets, and watches. The most common implementations are native, hybrid, and web apps.

A scalable mobile application infrastructure consists of a system designed to have no downtimes, no crashes, and be super fast and secure.

The essential elements of a scalable infrastructure include app publishing platforms, SDKs, APIs, CDNs, Load Balancers, and Application and Database servers.

The two most common ways to achieve a best-in-class scalable mobile app infrastructure are either using ready-to-solutions like a Backend as a Service or setting up a tailor-made backend on cloud services like AWS.

Backend as a service solutions will provide a faster implementation, out-of-the-box scaling features, and pre-defined security protocols. On the other hand, a custom-made backend will deliver a more flexible environment and control.

I hope you enjoyed reading this article and that it helped you better understand the foundations of a good mobile app architecture. If you do not want the hassles of creating, maintaining, and scaling a backend, please reach out to Back4App to learn more about how we can help you.

FAQ

What is a mobile app?

A mobile application works on devices like cellphones, tablets, and watches. The most common implementations are native, hybrid, and web apps.

How does a mobile app infrastructure looks like?

The essential elements of a scalable infrastructure include app publishing platforms, SDKs, APIs, CDNs, Load Balancers, and Application and Database servers.

How to create a scalable mobile app infrastructure?

The two most common ways to achieve a best-in-class scalable mobile app infrastructure are either using ready-to-solutions like a Backend as a Service or setting up a tailor-made backend on cloud services like AWS.


Leave a reply

Your email address will not be published.