Analysis / Contributed / Technology /

Reactive Programming for the New Mobile Stack

17 Oct 2017 11:00am, by

Alexander Stigsen
Alexander is co-founder and CEO of Realm, the leading mobile data platform embedded in over 3.5 billion mobile applications.

Where one technological advance starts, the rest of an industry must catch up to the potential of that technology with whatever tools they have. And that’s why, even though we’ve had an iPhone for a decade, we’re still struggling to make apps that make the most use of its capacities.

The problem wasn’t really all that much to do with the iPhone, but with the fact that most great apps aren’t that great until they connect to a server, and, consequently, to other users and clients. That’s the foundation for great mobile work. And it means that a mobile stack also requires a server and backend stack.

That server-side stack that mobile apps depend on looks a lot like the web stack, and follows web patterns because that’s where we started. We took server-side frameworks, made building RESTful APIs with them easier, and asked for JSON in response to the same requests our websites used to make. Those were the tools we had, and we’ve definitely made them work — in the last decade, it’s also become a lot easier to stream data instead of simply sticking to requests and responses, which sure feels a lot more natural for always-connected mobile devices.

When you finally get your backend and mobile teams together, you might notice just how much work it takes just to get the two stacks to talk to one another.

But the cost of building on top of a stack rooted in the web is enormous. When you finally get your backend and mobile teams together, you might notice just how much work it takes just to get the two stacks to talk to one another. For every view in an app, and every action you can take in that view, you must solve a difficult problem: how to make mobile apps speak in the language of a server-side world that evolved before we understood what mobile apps needed.

The biggest, most painful problem in making two incommensurate stacks work together is in dealing with your app’s data. First, you have to transport it. That means work building endpoints for your backend engineers, and work building and parsing requests to those endpoints for your mobile devs. And along the way, you’ll also have to serialize your data many times: from SQL on the backend’s database to JSON that can be sent over the wire, and finally to something that you can actually interact within a helpful way in a mobile app. And finally, you’ll need to persist that data so that it’s easy to use and performant to store and access, which currently means mastery over two distinct database technologies — like PostgreSQL on the server, and SQLite plus a related ORM on your device.

In every step of this delicate dance, there is fragility that shows itself whenever any code along this path changes. And that fragility takes its toll on your engineers on both teams.

Four Principles for the New Mobile Stack

If the problem is doing things with data, then the road to a solution lies in understanding what mobile apps need from their data and their databases.

Thinking about this set of problems, and how we’ve attacked them at Realm, I’ve developed four principles for the New Mobile Stack:

1. Event-driven

Mobile development must be event-driven, not request-driven. Apps are full of buttons and actions and the consequences of use, and HTTP requests or streaming protocols are the things into which we have to shoehorn those actions. As an alternative, let’s make it easy to create and sync the events at the core of your app’s behavior, and to react to those events on the client and server.

Along the way, we’ll end up moving a lot of our logic out of request success callbacks and into functions that are called as data is created or updated.

2. Data Must Flow

Data must flow, not be pushed or requested. We can take it for granted that app use will generate data. We should be able to take it for granted that that data can be synced to the server and to other clients without writing all the networking and serialization code that we currently are required to do. Data flow should be abstracted away from data operations, allowing you to focus on using that data for your users.

We’ll also need the ability to be explicit about how our data moves, by giving developers control over conflict resolution, and tools to let users know whether their data is fresh and actively syncing.

3. Data Sticks

When you go offline, the data should still there. Mobile use means you won’t always be connected — and right now, it just takes a closing elevator door for you to see just how tenuous your ability to use an app is. With persistent local data, you can still access, create, and edit the data that makes an app useful.

4. Pragmatic Logic

Any mobile dev should be able to write server-side and client-side logic. You shouldn’t have to rely on a backend team to ship a mobile feature. Instead, you ought to be able to write server-side, serverless code that reacts to data changes, as well as have access to an environment that lets you monitor and run that code without learning a whole new framework and language.

A New Hope: Putting the Mobile Stack into Practice

Taken together, these principles offer a mobile-first perspective on developing great apps. They enable greater developer productivity and happiness, and take away the enormous challenges we all have in simply trying to maintain sophisticated mobile apps. We just need the tools to be able to make these principles manifest.

New approaches have these ideas — in which reactivity underlies every operation — at the very core. By building seamless, real-time synchronization into the data layer from the start, it’s possible to sync data automatically between server and data with just a few lines of code for your whole app. That’s data that also stays in the local client database even when sync stops and it goes offline so that your app doesn’t go down with your user’s connection.

You also get all the server-side tools you need to build sophisticated apps, but with a mobile-first architecture — including access control and authentication that mobile developers can implement without a line of server-side code.

New mobile stacks are being built with the hope that developers can create the apps that they’re really dreaming of with technology that reflects what’s needed and works best on mobile. There is a learning curve for developers to learn how to build reactive mobile apps using these innovative tools that are part of the new mobile stack, which is why we created Realm Academy, a comprehensive and free repository of written, audio and video content and training on the most popular mobile development tools and methodologies, across Apple iOS, Google Android, and other mobile platforms. Aimed at experienced developers looking to learn and refine their skills working with the latest solutions, the goal is for everyone to be able to work without distractions, without sacrifices, or without having to constantly accommodate a stack that was in place long before anyone held an iPhone.

Feature image by Jamison McAndie, via Unsplash.


A digest of the week’s most important stories & analyses.

View / Add Comments

Please stay on topic and be respectful of others. Review our Terms of Use.