Background Processing in Applications

 

Every enterprise-level application uses background processing in some form. It may be a message passing interface implemented as a service bus, direct interaction via web sockets, or something else. We will check the most crucial areas in the background processing developer has to know and take care of.

User Experience

Tablet

The primary purpose of background processing is to shift activities that can be done in the background (usually asynchronously) to other computing nodes to balance a load and provide a better user experience to the customer. Let us split background tasks into two groups — the ones the customer wants to do right now and ones that can wait.

If the customer wants to get the result immediately, then the developer must minimize the response time. There are many ways to do that — set high priority for the task, set up more computing nodes, optimize the operation's performance, etc. Remember that the customer is not aware of when the task will be completed, so the developer must provide a proper interface and notification. The interface may include a progress bar, a list of activities done and left to do, and so on. Notification is needed to inform the customer that the task is completed and the result is ready. Please pay attention that the notification itself may be a background task, and it also has to be processed as soon as possible.

Tasks that can be done later usually can wait for several minutes or even hours. However, it is essential to understand when the results of these tasks have to be available ETA. Based on this time, the developer has to prioritize tasks and ensure that the system has enough resources to complete them in time. Unlike the urgent tasks, these less important tasks often do not require a separate notification. In many cases, it is enough to collect overall statistics (how many tasks of each type the system has processed) and send it daily, weekly, or even monthly.

Architecture and Scaling

Engines

The architecture of background and asynchronous processing assumes that there will be lots of computing nodes that have to communicate with each other. There has to be a standard interface responsible for message passing, processing, and collecting the result. In most cases, it is better to do not reinvent the wheel and use some existing solutions. There are many enterprise-level message-oriented and queue-based solutions that may satisfy most of the needs of any application.

It is crucial to use a proper solution for background and processing and build an application to allow the delegation of tasks to a separate computing node. Such an approach is essential to organize scaling and balance the load. If an application has to handle lots of low or medium complexity level requests, then scaling is the perfect solution. The system has to measure the load all the time and allow the developer to adjust the number of computing nodes based on the customers' demand. In many cases, an application can make such adjustments even automatically.

Performance Issues

Speedometer

Background processing often faces performance issues for several reasons.

The first reason is the fact that the customer does not see background processes. When the project manager or product owner selects an area for performance optimization, this is commonly something that can improve UX, not something happening under the bonnet. As a consequence, background processes consume lots of time and resources that can be spent elsewhere.

The second reason is the need for isolation. Application has to process each message on an entirely new setup to prevent the situation when one message may affect the other. Standard best practices include container-based environments or separate instances that are reset before the processing of each message. Such an approach ensures the required level of isolation, but at the same time adds a significant overhead because of environment reset.

Best Practices

Sticker With Bulb

As we saw, there are several best practices every enterprise application should consider for background processing.

Think ahead about the architecture and build the application to allow the delegation of operations to separate computing nodes. It includes responsibility separation, standard message interfaces, storage that supports parallel access, etc.

Prepare your application for scaling as this is the easiest way to handle lots of small and medium complexity tasks. It may include infrastructure tuning, automatic load balancing, and so on.

Finally, take care of background processing performance — the bigger the application, the more massive the computing nodes load. Measure the performance, track the bottlenecks, and fix found performance issues as soon as possible. Good performance optimization may save lots of time and resources.

Follow these best practices, and you will see the improvement in the way the application works and get a stable and reliable architecture for future development.