Improving System Performance and Availability with Reactive Programming: The Flower Framework
The Flower framework, built on Akka Actors, demonstrates how reactive programming’s responsive, resilient, elastic, and message‑driven principles can replace traditional blocking thread models with asynchronous, non‑blocking I/O, allowing a few container threads to handle many requests, doubling throughput, halving latency, and markedly improving system availability.
In recent years, reactive programming has become increasingly popular. The Reactive Manifesto defines four key principles: Responsive, Resilient, Elastic, and Message‑Driven. These principles aim to build systems that react promptly to requests, remain functional under failure, scale with workload, and communicate asynchronously.
The article examines why traditional backend development, which often relies on multithreaded blocking models (e.g., threads created by Tomcat), can lead to thread starvation and performance bottlenecks, especially when database access or slow queries block threads.
To address these issues, the authors describe the development of an all‑asynchronous reactive programming framework called Flower , built on Akka . Flower leverages Akka Actors for message‑driven communication and supports asynchronous database drivers, allowing requests to be handed off without blocking the container threads.
Key characteristics of Flower include:
Only a limited number of container threads are needed to handle a large number of concurrent user requests.
Service components communicate via asynchronous messages using Akka Actors.
Database interactions are performed asynchronously, preventing thread blockage during I/O.
Developers implement the Service interface to create reactive services. Example implementation:
public class ServiceA implements Service
{
@Override
public Object process(Message2 message) {
return message.getAge() + 1;
}
}Services are then composed into a processing flow:
getServiceFlow().buildFlow("ServiceA", "ServiceB");Performance tests conducted on typical products at Tongcheng Yilong show that after refactoring with Flower, throughput (TPS) doubled and average response time halved. Additionally, system availability improved because the gateway no longer blocks on slow downstream services; asynchronous HTTP calls keep the gateway responsive even when some services experience latency.
The authors conclude that reactive programming, exemplified by the Flower framework, aligns with historical trends of reducing coupling and increasing execution speed through concurrency, asynchronous I/O, and distributed architectures. They encourage readers to explore the open‑source project at https://github.com/zhihuili/Flower .
Tencent Cloud Developer
Official Tencent Cloud community account that brings together developers, shares practical tech insights, and fosters an influential tech exchange community.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.