Implementing Request and Other Approval Processes with Activiti
In modern enterprise application development, Business Process Management (BPM) plays a critical role. Whether handling leave requests, expense reimbursements, contract approvals, or complex supply chain lifecycles, organizations require efficient, flexible, and scalable engines to drive these dynamic business logics. As a lightweight, Java-centric open-source workflow engine, Activiti has become a classic choice for implementing various request and approval workflows, thanks to its standardized modeling capabilities and robust extensibility.
This article explores the core concepts of business engines, the underlying principles of Activiti, a comparative analysis with other workflow engines, and its comprehensive application landscape within enterprise architectures.
Before diving into specific engines, it is essential to clarify what a "business engine" entails. Broadly speaking, business engines encompass systems responsible for the automated execution of business logic, with two primary branches:
- Process Engines (such as Activiti): Focus on "where the process goes"—managing task routing, state control, human interaction, and step-by-step approvals.
- Rule Engines (such as Drools): Focus on "how the business is done"—handling complex decision-making, conditional calculations, and business rule configurations (note that this article focuses on the process engine layer).
The core value of a process engine lies in decoupling hard-coded business workflows from application code, defining them instead through graphical modeling—typically based on the BPMN 2.0 standard. This not only enhances business transparency but also significantly shortens the cycle of business changes.
Activiti is a Java-based open-source workflow engine designed for lightweight deployment, portability, and high extensibility. Understanding Activiti requires mastering its core architectural mechanisms:
- BPMN 2.0 Standard Support: Activiti strictly adheres to the OMG BPMN 2.0 specification. This allows developers to use plugins in tools like IntelliJ or Eclipse, or web-based modelers, to draw standard process diagrams (in XML format) that the engine can directly parse and execute.
- Core Service Components: Activiti provides a rich set of APIs through dedicated services to interact with process data stored in the database:
RepositoryService: Manages process definitions and deployment resources, such as BPMN models and images.RuntimeService: Manages runtime data, including starting, advancing, and suspending process instances.TaskService: Manages user tasks, covering operations like claiming, completing, and delegating approval tasks.HistoryService: Handles historical data queries used for auditing, reporting, and tracking.
- Persistence and Database: Activiti utilizes MyBatis as its default persistence layer, supporting mainstream relational databases like MySQL, Oracle, and PostgreSQL. It automatically initializes over twenty database tables prefixed with
ACT_, ensuring a clean separation between engine runtime data and core business data.
Workflow Engine Comparison: How to Choose?
In the open-source workflow ecosystem, developers often weigh different technology stacks. To better understand Activiti’s positioning, we can evaluate it against other mainstream engines in the market:
- Activiti / Flowable Camp:
- Characteristics: Long-standing pillars in the Java ecosystem with mature API designs, rich documentation, and massive communities. Flowable evolved from earlier versions of Activiti, sharing a high degree of architectural similarity. Both excel at handling standard human-centric approval workflows.
- Use Cases: Traditional enterprise applications, SaaS platforms, and systems requiring deep customization and strong Java integration.
- Camunda Camp:
- Characteristics: Emphasizes high throughput and powerful operational monitoring capabilities, with particular strength in DMN (Decision Model and Notation) and CMMN (Case Management Model and Notation) support.
- Use Cases: Large enterprises with extreme performance demands and distributed process engines within microservices architectures.
- Lightweight or Language-Specific Engines (such as Zeebe and Temporal):
- Characteristics: Tailored for cloud-native and microservices architectures, supporting asynchronous, high-concurrency orchestration without relying heavily on relational databases, often utilizing event sourcing.
Through this comparison, it is clear that Activiti remains a robust choice for standard human-to-system interaction processes like requests and approvals, offering a gentle learning curve and a comprehensive ecosystem.
Application Landscape: Implementing Approval Workflows in Enterprise Systems
Implementing a complete request and approval process using Activiti in a real-world business environment typically follows a full lifecycle:
- Process Modeling and Design
Business analysts and developers collaborate to draw approval flows using the BPMN 2.0 specification. For instance, a leave application process includes: Start Event -> Submit Leave Application (User Task) -> Department Manager Approval (User Task) -> Conditional Gateway (Approved/Rejected) -> End Event. - Resource Deployment and Integration
The exported.bpmn20.xmlfile is packaged into the application and deployed to the Activiti engine viaRepositoryService. When the backend receives a leave request from the frontend, it invokesRuntimeService.startProcessInstanceByKeyto initiate a process instance. - Task Interaction and Routing
- The department manager logs into the system and queries pending tasks using
TaskService.createTaskQuery(). - After reviewing, the manager invokes
TaskService.complete(taskId, variables)to submit the approval outcome, passing parameters for approval or rejection. - The engine automatically computes the next step based on gateway conditions defined in the process: if rejected, the process ends; if approved, it routes to the HR archiving node.
- The department manager logs into the system and queries pending tasks using
- Historical Archiving and Monitoring
Once an approval concludes, all historical instances, comments, and durations are preserved in historical tables. Management can review the complete approval trajectory of any request at any time usingHistoryService.
Conclusion
Implementing request and approval workflows through Activiti not only liberates tedious business logic from application code but also enhances system maintainability and scalability through standardized modeling. Mastering Activiti's core principles and understanding its ecological positioning in enterprise architecture provides a reliable pathway for building efficient and flexible business approval systems. As business complexity grows, further exploration of advanced features—such as asynchronous tasks, custom listeners, and multi-tenancy support—can empower the process engine to drive even greater value for the enterprise.