Background Processing for React Native Applications in 2022
Tags: reactnative, backgroundprocessing, software, javascript
Published: 2022-07-25 20:25:00

_A background process does work for a computer in a way that optimizes performance of the user interface. [If you are new to background processing, check out this article](https://dev.to/christophertdoc/what-are-background-processes-in-computing-e46). There are several options for background processing regarding react native applications, each with their own trade-offs and levels of built-in functionality. The following is a brief overview of each option along with a list of advantages and disadvantages._

---

## [React Native Background Fetch](https://www.npmjs.com/package/react-native-background-fetch)
This is a fairly simple but well maintained background worker created by a company called [Transistor Software](https://www.transistorsoft.com/) which specializes in making native location API’s that run in the background. React native background fetch will perform periodic work once every 15 minutes and works on both Android and iOS.

### Advantages
- Well maintained
- Works on both android AND iOS

### Disadvantages
- Only a periodic worker (no support for queue)
- Only runs once every 15 minutes. There is no way to speed this up.
- Not very many features.

---

## [React Native Background Task](https://www.npmjs.com/package/react-native-background-task)
This module is very similar to react-native-background-fetch in that it offers iOS and Android support for a periodic worker that executes a task no faster than once every 15 minutes. It offers a few different features as compared to react-native-background-fetch but is NOT maintained and has some pretty restrictive limitations.

### Advantages
- Works on both android AND iOS

### Disadvantages

- Not well maintained
- Only offers a periodic worker that runs once every 15 minutes.
- Has some pretty [restrictive limitations](http://react-native-background-fetch/) such as tasks not being run while the app is in the foreground for Android and tasks are not able to run if the user manually closes the app on iOS.

---

## [React Native Background Worker](https://github.com/JoaoLSS/react-native-background-worker)
React Native Background Worker offers the most amount of features as compared with the other options. It has the ability to do periodic work OR manage a queue of tasks among other things. It is built on [Android SDK’s own feature-rich WorkManager API](https://developer.android.com/topic/libraries/architecture/workmanager). Despite having some of these advantages, it also has some downsides including NOT being well maintained and having at least one feature that no longer works ([canceling a task](https://github.com/JoaoLSS/react-native-background-worker#cancel)). Still though, this module does have some nice features and if someone were to maintain it and incorporate even just a little more of Android WorkManager’s functionality, this module would be a home run for background processing on Android applications.

### Advantages
- Offers queue AND periodic worker options.
- Includes more functionality as compared to other options.

### Disadvantages
- Not well maintained.
- Can only be used for android.

---

## [Headless JS](https://reactnative.dev/docs/headless-js-android)
Headless JS is react-native’s own approach to executing processes for Android only. It utilizes [Android SDK’s Services application component](https://developer.android.com/guide/components/services?authuser=1) and does require that you write some native code in order to get it up and running. Further, headless JS only offers some basic features such as the ability to specify how headless JS will approach retrying tasks (in case of failure). If you need to manage a queue of tasks or even periodic work on tasks, you’ll have to write this functionality yourself.

### Advantages
- Well maintained and supported by react-native.
- Customizable retry policy.

### Disadvantages
- Requires that you write some native code.
- Does not have a whole lot of features such as managing periodic or queue work.
- Only works on Android (NOT on iOS)

---

## (Coming Soon) [React Native Background Queue Processor](https://github.com/technogise/rn-background-queue-processor)
...

---

## Conclusion
_There is not ONE module that includes all of the best functionality for both iOS and Android. Instead, we are left with only several options that have some trade-offs. However, I DO believe there is currently a best option for each platform. For android, the best options are react-native-background-worker for being feature-rich and react-native-background-fetch for its simplicity of use and being well maintained. For iOS, again the best option here would be react-native-background-fetch for the same reasons as Android. Ideally in the future though, there is great opportunity to improve on background processing for react-native applications. If someone were to take over and further enhance react-native-background-worker and offer support for iOS on that module, that would be a big win for the react-native ecosystem._