Why Kafka + PostgreSQL?
- Kafka: High-throughput, distributed message broker with excellent scalability
- PostgreSQL: Robust relational database with strong consistency guarantees
- Use case: Production deployments requiring high message throughput and reliable persistence
Prerequisites
- Docker and Docker Compose installed
- Lemline built locally (see Installation)
- Basic understanding of Kafka and PostgreSQL
Quick Start
# Lemline Configuration: Kafka + PostgreSQL
lemline:
database:
postgresql:
host: localhost
port: 5432
database: lemline
username: postgres
password: postgres
messaging:
kafka:
brokers: localhost:9092
LEMLINE_CONFIG=./examples/lemline-kafka-pg.yaml \
java -jar lemline-runner/build/quarkus-app/quarkus-run.jar listen
commands-in, commands-out, events-out)Configuration Details
PostgreSQL Settings
Kafka Settings
Database Schema
Lemline automatically creates the necessary tables:- workflow_definitions: Workflow DSL definitions
- workflow_instances: Active and completed workflow instances
- workflow_waits: Scheduled tasks and timeouts
- workflow_listeners: Event listeners and subscriptions
- workflow_retries: Retry state for failed tasks
- workflow_failures: Terminal failures and errors
- lifecycle_analytics: Execution metrics and history
Kafka Topics
Lemline uses three Kafka topics by default:- commands-in: Incoming workflow commands (start, resume, cancel)
- commands-out: Outgoing workflow commands for task execution
- events-out: CloudEvents produced by workflows
Topic Configuration
Kafka creates topics automatically with default settings (4 partitions, replication factor 1). For production, pre-create topics with appropriate settings:Horizontal Scaling
Run multiple Lemline instances to scale horizontally:Monitoring
Kafka UI
Access the Kafka UI at http://localhost:8080 to:- View topics and partitions
- Inspect messages
- Monitor consumer lag
- View broker metrics
PostgreSQL Monitoring
Connect to PostgreSQL to query workflow state:Production Considerations
Database connection pooling
Database connection pooling
Configure appropriate pool sizes based on your workload:
Kafka broker configuration
Kafka broker configuration
For production, use a multi-broker Kafka cluster with:
- At least 3 brokers for fault tolerance
- Appropriate replication factor (typically 3)
- Sufficient partitions for parallelism (8-16 per topic)
PostgreSQL tuning
PostgreSQL tuning
Optimize PostgreSQL for your workload:
- Increase
max_connectionsfor concurrent workflows - Tune
shared_buffersandeffective_cache_size - Enable connection pooling with PgBouncer
- Configure appropriate backup and replication
Security
Security
- Use TLS for Kafka connections
- Enable PostgreSQL SSL
- Use strong passwords and rotate credentials
- Configure Kafka SASL authentication
- Restrict network access with firewalls
Troubleshooting
Kafka Connection Refused
Error:Connection to node -1 (localhost/127.0.0.1:9092) could not be established
Solution: Ensure Kafka is running and accessible:
PostgreSQL Connection Errors
Error:Connection refused or password authentication failed
Solution: Check PostgreSQL status and credentials:
Topic Not Created
Error:Topic 'lemline-commands-in' does not exist
Solution: Kafka auto-creates topics by default. If disabled, manually create topics (see Kafka Topics).
Stopping the Infrastructure
Next Steps
RabbitMQ + MySQL
Try a different messaging/database combination
PGMQ Setup
Use PostgreSQL for both messaging and storage
Production Deployment
Deploy Lemline to production
Monitoring
Set up metrics and monitoring