Process Orchestration: The Survival Skill for Multi-Business Backend Systems
The article explains why process orchestration is essential for backend systems serving multiple business lines, demonstrating a flow engine with process, success, rollback, and callback nodes that eliminates if-else chains, ensures code isolation, and enables safe extension, with code examples and a Git repository reference.
As a backend engineer, the author initially dismissed process orchestration as overdesign, preferring straightforward code. However, after joining a middleware team that had to onboard many business lines with varying requirements, he realized that without orchestration the codebase becomes a tangle of if-else branches — each new business adds more conditional logic, making changes risky and regression testing impractical.
Problem: If-Else Hell in Multi-Business Systems
When 10+ business lines share a single codebase, developers cannot know every business flow. A change for one line can inadvertently break another, and full regression across all lines is unrealistic. The core issues are code isolation and business extension points .
if (biz == BizA || biz == BizB) {
// shared logic
if (biz == BizA) {
// BizA-specific handling
}
if (biz == BizB) {
// BizB-specific logic
}
}Solution: Flow Engine + Plugin Extension Engine
Flow engine – configure a distinct execution chain for each business.
Plugin extension engine – implement differentiated logic via plugins.
The author's project MemberClub uses both engines heavily.
Configuring Execution Chains
Different member products have different purchase flows. DemoMemberPurchaseExtension implements the purchase extension point and defines three chain configurations.
Defining Flow Nodes
Each flow node contains four methods: process, success, rollback, and callback.
Flow Execution
Execution starts by providing a flow context object and calling FlowChain.execute. The engine chains nodes sequentially, similar to the Chain of Responsibility pattern:
Execute each node's process method in order.
If a process throws an exception, run rollback on already-executed nodes in reverse order.
If all process calls succeed, run success on all nodes in reverse order.
Finally, run callback on all nodes in reverse order (always executed).
A SkipException stops further process execution but still triggers callback.
FlowChain.execute Implementation
The core execution logic is shown below. It tracks the last successful index, handles exceptions, performs rollback or success phases, and always runs callbacks.
public <T> void execute(FlowChain<T> chain, T context) {
Exception exception = null;
int index = -1;
for (FlowNode<T> node : chain.getNodes()) {
try {
node.process(context);
index++;
} catch (Exception e) {
if (e instanceof SkipException) {
CommonLog.warn("当前流程:{} 发出 Skip请求,后续流程不再执行", node.getClass().getSimpleName());
break;
}
exception = e;
break;
}
}
if (exception != null) {
for (int i = index; i >= 0; i--) {
FlowNode<T> node = chain.getNodes().get(i);
try {
node.rollback(context, exception);
} catch (Exception e) {
CommonLog.error("rollback执行异常,忽略 name:{}", node.getClass().getSimpleName(), e);
}
}
} else {
for (int i = index; i >= 0; i--) {
FlowNode<T> node = chain.getNodes().get(i);
try {
node.success(context);
} catch (Exception e) {
CommonLog.error("success 执行异常,忽略 name:{}", node.getClass().getSimpleName(), e);
}
}
}
for (int i = index; i >= 0; i--) {
FlowNode<T> node = chain.getNodes().get(i);
try {
node.callback(context, exception);
} catch (Exception e) {
CommonLog.error("callback执行异常,忽略 name:{}", node.getClass().getSimpleName(), e);
}
}
if (exception != null) {
throw exception;
}
}Source Code Repository
The complete implementation is available at: https://gitee.com/juejinwuyang/memberclub
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
IoT Full-Stack Technology
Dedicated to sharing IoT cloud services, embedded systems, and mobile client technology, with no spam ads.
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.
