Lemline documentation Help

Why Event-Driven Orchestration Beats the Database

This explanation explores the architectural advantages of Lemline's event-driven orchestration approach compared to traditional database-centric workflow engines. We'll examine the problems with conventional state persistence, explain event-driven principles, and analyze the performance implications.

The Problem with Traditional State Persistence

Traditional workflow engines share a common architectural pattern: they rely heavily on a central database to store workflow state. While this approach seems logical at first glance, it introduces significant challenges:

Database Transaction Overhead

Every workflow step in traditional engines typically requires multiple database transactions:

  1. Read state: Retrieve the current workflow state from the database

  2. Lock state: Acquire locks to prevent concurrent modifications

  3. Execute logic: Perform the actual business logic

  4. Update state: Save the updated workflow state

  5. Update history: Record execution history and audit trail

  6. Release locks: Free resources for other transactions

This pattern creates several issues:

  • Transaction Volume: Even simple workflows generate high transaction volumes

  • Lock Contention: Concurrent workflows compete for the same database resources

  • Transaction Duration: Long-running tasks hold database connections and locks

  • Write Amplification: Each logical step requires multiple physical writes

Performance Bottlenecks

The database quickly becomes the performance bottleneck:

  • I/O Limitations: Database performance is ultimately constrained by disk I/O

  • Connection Pools: Limited connection pools restrict throughput

  • Scaling Challenges: Vertical scaling becomes necessary, which is expensive and has limits

  • Backup and Recovery: Larger databases take longer to backup and restore

  • Index Maintenance: Indexes needed for performance consume additional resources

A medium-sized workflow system can easily generate millions of database operations per day, even with modest workflow volumes.

High Infrastructure Costs

The infrastructure requirements grow rapidly:

  • Expensive Storage: Need for high-performance SSD storage

  • Memory Requirements: Large buffer pools for acceptable performance

  • CPU Overhead: Transaction processing consumes substantial CPU resources

  • Backup Storage: Large databases require significant backup capacity

  • High Availability: Replication and failover systems add more complexity

Reliability Challenges

Centralizing all state in a database introduces single points of failure:

  • Database Availability: If the database is down, all workflow processing stops

  • Complex Recovery: Recovering from database failures is non-trivial

  • Transaction Boundaries: Determining proper transaction boundaries is challenging

  • Partial Failures: Handling failures mid-transaction requires complex compensation logic

  • Data Consistency: Maintaining consistency across distributed systems is difficult

Event-Driven State Management Principles

Lemline takes a fundamentally different approach by embracing event-driven architecture principles:

Event Sourcing Foundation

Instead of storing the current state, Lemline applies event sourcing concepts:

  • Events as Truth: The sequence of events becomes the source of truth

  • Derived State: Current state is derived from the event sequence when needed

  • Immutable History: Events are immutable facts about what happened

  • Natural Audit Trail: Event history provides a built-in audit trail

This approach decouples state management from persistence concerns.

Message-First Architecture

Rather than using the database as the primary communication medium, Lemline uses messaging:

  • Event Communication: Components communicate through events

  • Asynchronous Processing: Tasks can execute asynchronously

  • Natural Parallelism: Independent operations run in parallel automatically

  • Loose Coupling: Components don't need direct knowledge of each other

This messaging foundation enables a more resilient and scalable system.

Selective Persistence Strategy

Lemline only persists state when absolutely necessary:

  • Wait States: Persistent storage for time-based operations

  • Event Correlation: Storage for matching related events

  • Long-Running Operations: Persistence for operations spanning days or weeks

  • Outbox Pattern: Reliable message delivery with transactional guarantees

For many workflow types, most execution can happen without touching a database at all.

The Architecture Advantages

Minimal Database Interaction

In a traditional system, a 10-step workflow might require 30+ database operations. In Lemline, the same workflow might need only 2-3 database operations, or none at all for short-lived workflows.

Consider this comparison for a payment processing workflow:

Workflow Step

Traditional Engine

Lemline

Receive order

3 DB operations

0 DB operations

Validate order

2 DB operations

0 DB operations

Check inventory

3 DB operations

0 DB operations

Process payment

3 DB operations

0 DB operations

Generate invoice

3 DB operations

0 DB operations

Wait for shipping

3 DB operations

1 DB operation

Send confirmation

3 DB operations

0 DB operations

Complete order

3 DB operations

0 DB operations

Total

23 DB operations

1 DB operation

This dramatic reduction in database operations translates directly to higher throughput, lower latency, and reduced infrastructure costs.

Horizontal Scalability

Event-driven architectures enable true horizontal scalability:

  • Stateless Processing: Most processing can be stateless

  • Partition-Based Scaling: Scale by adding more processing nodes

  • Natural Load Distribution: Message brokers distribute load across nodes

  • No Central Bottleneck: No single component limits overall throughput

  • Independent Scaling: Scale individual components based on their specific needs

Resilience to Failures

The event-driven approach provides superior resilience:

  • Inherent Fault Isolation: Component failures don't bring down the entire system

  • Message Replay: Events can be replayed from the broker if needed

  • Reduced Failure Domain: Each component has a smaller failure domain

  • Simpler Recovery: Recovery often means simply restarting a component

  • Graceful Degradation: System can continue operating in degraded modes

Lower Operational Costs

Operational costs are significantly reduced:

  • Reduced Database Size: Much smaller database footprint

  • Lower IOPS Requirements: Fewer database operations mean lower IOPS needs

  • Cheaper Storage Options: Less demanding storage requirements

  • Simplified Backup: Smaller databases are easier to backup and restore

  • Lower Memory Needs: Less data needs to be cached in memory

When Lemline Uses a Database (and Why)

While Lemline minimizes database usage, it still leverages databases for specific scenarios:

Wait States and Timers

When a workflow needs to pause execution for a period of time:

document: dsl: 1.0.3 namespace: examples name: wait-states-and-timers version: 1.0.0 do: - waitForPaymentWindow: wait: PT10S then: checkPaymentStatus - checkPaymentStatus: set: windowClosed: true

This wait operation is stored in the database with:

  • Workflow instance ID

  • Current position

  • Wake-up time

  • Next task to execute

A dedicated outbox processor periodically checks for expired waits and resumes the workflow.

Event Correlation

When workflows need to correlate incoming events:

document: dsl: 1.0.3 namespace: examples name: event-correlation version: 1.0.0 do: - waitForShipmentEvents: listen: to: one: with: type: com.example.shipment.updated correlate: orderId: from: ${ .orderId } expect: ${ $workflow.input.orderId } then: processShipmentUpdates - processShipmentUpdates: set: orderId: ${ .[0].orderId } status: ${ .[0].status }

The correlation criteria are stored in the database to match against incoming events.

Outbox Pattern Implementation

For guaranteed message delivery, Lemline uses the outbox pattern:

  1. Database transaction inserts the message into an outbox table

  2. Dedicated processor reads from the outbox and publishes to the message broker

  3. After successful publication, the message is marked as processed

This ensures exactly-once message delivery semantics with transactional guarantees.

Storage Efficiency

When Lemline does use the database, it's designed for maximum efficiency:

  • Minimal Schema: Tables contain only essential fields

  • Optimized Indexes: Carefully designed indexes for common query patterns

  • TTL Mechanisms: Automatic purging of completed entries

  • Batch Processing: Processing multiple records in batches

  • Connection Pooling: Efficient connection management

Performance Implications

Benchmark Comparisons

Benchmarks comparing Lemline to traditional workflow engines show significant performance advantages:

Throughput (workflows per second)

Scenario

Traditional Engine

Lemline

Improvement

Simple workflows

100

500+

5x

Medium complexity

50

200+

4x

Complex workflows

20

60+

3x

Latency (average workflow execution time)

Scenario

Traditional Engine

Lemline

Improvement

Simple workflows

500ms

100ms

5x

Medium complexity

1000ms

300ms

3.3x

Complex workflows

2500ms

800ms

3.1x

Resource Utilization (relative to traditional engine)

Resource

Traditional Engine

Lemline

Database IOPS

100%

10-20%

Database storage

100%

15-30%

Database connections

100%

20-40%

Memory usage

100%

60-80%

CPU usage

100%

70-90%

Real-World Performance Characteristics

In production environments, Lemline demonstrates these characteristics:

  • Linear Scaling: Performance scales linearly with added nodes

  • Low Latency: Consistently low latency even under high load

  • Predictable Behavior: Performance remains stable and predictable

  • Burst Handling: Can handle sudden spikes in traffic

  • Resource Efficiency: Makes efficient use of available resources

When to Choose Each Approach

While event-driven orchestration offers significant advantages, there are scenarios where database-centric approaches might still be appropriate:

Choose Event-Driven Orchestration When:

  • High-volume workflows: Processing thousands of workflows per minute

  • Performance-sensitive scenarios: Low latency requirements

  • Cost-sensitive deployments: Need to minimize infrastructure costs

  • Horizontally scalable environments: Cloud-native or microservices architectures

  • Resilience is critical: Need for high availability and fault tolerance

Database-Centric May Still Make Sense When:

  • Very low volume workflows: Just a few workflows per day

  • Complex transactions: Need for ACID semantics across multiple operations

  • Legacy integration: Tight integration with existing database-centric systems

  • Simplified operations: When operational simplicity outweighs performance

Implementation Considerations

When adopting event-driven orchestration, consider these implementation factors:

Message Broker Selection

The message broker becomes a critical component:

  • Reliability: Choose a broker with strong delivery guarantees

  • Throughput: Ensure the broker can handle your expected message volume

  • Latency: Consider message delivery latency requirements

  • Partitioning: Efficient partitioning for scalability

  • Management: Operational simplicity and monitoring capabilities

Event Schema Design

Well-designed event schemas are essential:

  • Versioning: Include schema versions for forwards/backwards compatibility

  • Self-Contained: Events should contain all necessary context

  • Correlation IDs: Include identifiers for tracing related events

  • Timestamps: Include event creation time

  • Explicit Types: Clearly identify event types

Observability

With distributed processing, observability becomes critical:

  • Distributed Tracing: Implement tracing across components

  • Metrics Collection: Gather metrics from all parts of the system

  • Centralized Logging: Aggregate logs for comprehensive visibility

  • Correlation IDs: Use consistent correlation IDs for tracking

  • Health Monitoring: Monitor the health of all components

Run the Examples

Every example on this page is a complete workflow. Complete the SQLite setup, save each example under the file name used below, and run the commands from the setup directory. With the JAR, substitute java -jar lemline.jar for bin/lemline.

The event examples need the tutorial publisher. Save it as tutorial-publisher.yaml:

document: dsl: '1.0.3' namespace: examples name: tutorial-publisher version: '1.0.0' do: - publish: emit: event: with: type: ${ .type } source: https://events.example.com/tutorial data: ${ .data }

Keep the setup worker running and use a second terminal in the setup directory.

bin/lemline definition post -f tutorial-publisher.yaml bin/lemline definition post -f wait-states-and-timers.yaml bin/lemline instance start examples wait-states-and-timers bin/lemline definition post -f event-correlation.yaml bin/lemline instance start examples event-correlation --input '{"orderId":"ORD-1801"}' bin/lemline instance start examples tutorial-publisher --input '{"type":"com.example.shipment.updated","data":{"orderId":"OTHER","status":"in-transit"}}' bin/lemline instance start examples tutorial-publisher --input '{"type":"com.example.shipment.updated","data":{"orderId":"ORD-1801","status":"delivered"}}'

Example

Expected result

wait-states-and-timers

{"windowClosed":true} 10 to 20 seconds later: the worker picks up timers every 10 seconds

event-correlation

Ignores the update for OTHER, then completes with {"orderId":"ORD-1801","status":"delivered"}

Conclusion

Lemline's event-driven orchestration offers a fundamentally different approach to workflow execution that overcomes many limitations of traditional database-centric engines. By minimizing database interactions, embracing event-driven principles, and selectively using persistence only when necessary, Lemline achieves superior performance, scalability, and resilience while reducing operational costs.

The key takeaways:

  1. Database Overhead Matters: Traditional workflow engines generate excessive database load

  2. Events as First-Class Citizens: Treating events as the primary communication mechanism enables better architectures

  3. Selective Persistence: Only persist what's absolutely necessary

  4. Significant Performance Gains: Event-driven orchestration delivers measurable performance improvements

  5. Cost Reduction: Lower infrastructure requirements translate to cost savings

  6. Improved Resilience: More resilient to component failures and better fault isolation

For most modern workflow scenarios, event-driven orchestration provides a superior approach that aligns well with cloud-native, microservices, and distributed system architectures.

25 November 2026