This document presents a scalable approval workflow system architecture designed to handle complex multi-step business processes with intelligent routing, parallel processing capabilities, and comprehensive audit trails for enterprise-grade applications.
1. Executive Summary
Clarifying questions
-
What is the expected read/write ratio for approval requests and actions?
- Understanding this helps size caching layers and database throughput requirements.
-
What are the consistency requirements for approval workflows?
- Are approvals immediately visible across systems, or eventual consistency acceptable?
-
Is this a global system with multi-region support needed?
- Affects data replication strategy and latency-sensitive design decisions.
-
How sensitive is the system to end-to-end latency?
- Critical for determining whether to use synchronous or asynchronous workflows.
-
What are the data ownership and compliance requirements (e.g., GDPR, HIPAA)?
- Influences storage strategy, encryption, and audit logging.
-
Are there external systems that need to integrate with the approval system (e.g., HR, finance)?
- Impacts messaging and event-driven architecture decisions.
-
What is the expected growth in approval requests and users over 12 months?
- Helps size infrastructure and calculate bandwidth/storage needs.
Problem being solved
The Approval Workflow System is designed to manage multi-step approval processes across various business domains (e.g., expense claims, document reviews, system changes). It enables organizations to define approval rules, route requests dynamically based on business logic, and track the status of each approval step in real-time. The system must support flexible workflows, audit trails, and scalability to handle hundreds of thousands of concurrent approval processes.
Back-of-envelope calculations
Assuming:
- 1 million DAU (Daily Active Users)
- Peak-to-average ratio of 10:1
- Average approval request per user = 5/month → ~1,000 approvals/day
- Peak QPS = 1,000 * 10 = 10,000 QPS
Storage per user/approval:
- Average approval request size = 2KB
- Average approval history (metadata + comments) = 1KB
- Total storage per user = ~3KB/month → ~36GB/year/user
Total storage growth:
- 1M users * 36GB = 36TB/year
Bandwidth (read + write):
- Write throughput: 10,000 QPS * 2KB = 20MB/s
- Read throughput: 10,000 QPS * 1KB = 10MB/s
- Total: 30MB/s
Cache hit rate assumption: 85%
- DB QPS = 10,000 * (1 - 0.85) = 1,500 QPS
Server capacity estimate (per server):
- Per-server throughput = 5,000 QPS
- Number of servers needed at peak = 1,500 / 5,000 = ~3 servers
SLA targets
- P50 Latency: < 100ms (critical path)
- P95 Latency: < 500ms
- P99 Latency: < 2s
- Availability: 99.9% (3.6 minutes downtime/month)
- Durability: RPO < 5 minutes
- Consistency: Eventual consistency for non-critical workflows, strong consistency for financial or compliance approvals
Key architectural decisions summary
- Microservices-based architecture to support modular workflows and independent scaling.
- Event-driven design for asynchronous approval routing and notifications.
- Relational DB (PostgreSQL) for audit trail and approval state management.
- Caching layer using Redis to reduce DB load and improve response times.
- Multi-region support for high availability and disaster recovery.
- Service mesh (Istio) to manage cross-service communication, observability, and security.
- Authentication via OIDC with RBAC for fine-grained access control.
- Compliance-first design to meet enterprise security and audit requirements.
2. System Goals & Non-Functional Requirements
Latency Targets
- p50: 200ms for approval request creation and status updates
- p95: 500ms for approval workflows with complex routing
- p99: 1000ms for approval workflows with multi-step routing and notifications
- Critical path: Approval request creation, status update, and notification delivery
Throughput Requirements
- Average QPS: 5000 requests/sec for approval workflows
- Peak QPS: 50,000 requests/sec (10x average) during business hours
- Peak-to-average ratio: 10:1 (based on typical business hour patterns)
- Approval request processing rate: 1000 requests/sec for concurrent approvals
Availability Target
- 99.9% (3 nines) availability for core approval workflow functionality
- 99.99% (4 nines) for mission-critical approval paths (e.g., financial approvals)
- Justification:
- Business-critical workflows require high availability to prevent operational delays
- Non-critical workflows can tolerate brief outages with manual fallback capability
Durability and Consistency Requirements
- Consistency Model: Eventual consistency for approval status updates, strong consistency for approval decisions and audit trails
- Durability: All approval decisions must be persisted with RPO < 1 minute for critical workflows
- CAP Trade-off: Prioritize consistency over availability in approval decision paths to ensure auditability and compliance
- Data Replication: Multi-region replication with synchronous writes for approval decisions, asynchronous for status updates
Data Retention and Compliance Requirements
- Approval Decision Data: Retain for 7 years (compliance with financial regulations)
- Audit Logs: Retain for 10 years (audit compliance requirements)
- User Access Logs: Retain for 2 years
- Compliance Frameworks: GDPR (data privacy), HIPAA (healthcare data), SOX (financial reporting)
- Data Classification: Tiered classification (public, internal, confidential, highly confidential)
Security and Regulatory Requirements
- Authentication: OAuth2/OIDC with multi-factor authentication for approval decision-makers
- Authorization: Role-based access control (RBAC) with granular permissions per approval level
- Data Encryption: AES-256 encryption at rest and TLS 1.3 in transit
- Audit Trail: Complete audit trail of all approval actions with timestamps and user identities
- Compliance:
- GDPR compliance for data handling and user consent management
- HIPAA compliance for healthcare-related approvals
- SOC2 Type II for security and availability controls
- Access Control:
- Approval routing based on organizational hierarchy and role assignments
- Approval delegation with time-bound permissions
- Audit trail for all approval actions and rejections
3. High-Level Architecture Diagram
C4Context
title Approval Workflow System - Context Diagram
Person(user, "End User")
Person(approver, "Approver")
Person(admin, "System Admin")
System_Boundary(b1, "Approval Workflow System") {
System(aws, "AWS Services")
System(auth, "Authentication Service")
System(api, "API Gateway")
System(workflow, "Workflow Engine")
System(notifications, "Notification Service")
System(orchestration, "Orchestration Service")
System(db, "Database Layer")
System(cache, "Caching Layer")
System(message, "Message Broker")
System(search, "Search Service")
}
System_Ext(ext1, "External Systems")
System_Ext(ext2, "Payment Gateway")
System_Ext(ext3, "Email Service")
Rel(user, api, "Initiates approval requests")
Rel(approver, api, "Approves/rejects")
Rel(admin, api, "Manages workflows")
Rel(api, auth, "Authenticates users")
Rel(api, workflow, "Routes requests")
Rel(api, notifications, "Sends notifications")
Rel(api, orchestration, "Manages state transitions")
Rel(workflow, db, "Stores workflow data")
Rel(workflow, cache, "Caches workflow state")
Rel(workflow, message, "Publishes events")
Rel(orchestration, db, "Manages approval state")
Rel(orchestration, message, "Consumes events")
Rel(notifications, ext3, "Sends email notifications")
Rel(ext1, api, "Integrates with external systems")
Rel(ext2, api, "Handles payment approvals")
UpdateLayoutConfig($c4ShapeInRow = 3)
C4Container
title Approval Workflow System - Container Diagram
Container_Boundary(c1, "Approval Workflow System") {
Container(web, "Web API", "Go/Gin", "Handles REST requests")
Container(mobile, "Mobile API", "Go/Gin", "Handles mobile requests")
Container(auth, "Auth Service", "Node.js/Express", "Handles authentication and authorization")
Container(workflow, "Workflow Engine", "Go/Gin", "Core workflow logic and state management")
Container(orchestration, "Orchestration Service", "Go/Gin", "Manages approval state transitions")
Container(notifications, "Notification Service", "Go/Gin", "Handles email/SMS notifications")
Container(search, "Search Service", "Elasticsearch", "Enables search and filtering of workflows")
Container(cache, "Redis Cache", "Redis", "Caches workflow state and user data")
Container(db, "Database Layer", "PostgreSQL", "Stores workflow definitions, instances, and audit logs")
Container(message, "Message Broker", "Kafka", "Handles asynchronous events and notifications")
Container(metrics, "Metrics Service", "Prometheus + Grafana", "Collects and visualizes system metrics")
Container(tracing, "Distributed Tracing", "Jaeger", "Traces requests across services")
}
Container_Ext(ext1, "External Systems", "Third-party integrations")
Container_Ext(ext2, "Payment Gateway", "External Payment System")
Container_Ext(ext3, "Email Service", "SendGrid/SES")
Rel(web, auth, "Authenticates")
Rel(web, workflow, "Requests approval workflows")
Rel(mobile, auth, "Authenticates")
Rel(mobile, workflow, "Requests approval workflows")
Rel(workflow, orchestration, "Manages state transitions")
Rel(workflow, notifications, "Sends notifications")
Rel(workflow, search, "Searches workflows")
Rel(workflow, cache, "Caches workflow state")
Rel(workflow, db, "Stores data")
Rel(workflow, message, "Publishes events")
Rel(orchestration, db, "Manages approval state")
Rel(orchestration, message, "Consumes events")
Rel(notifications, ext3, "Sends emails")
Rel(ext1, workflow, "Integrates with external systems")
Rel(ext2, workflow, "Handles payment approvals")
Rel(metrics, web, "Collects metrics")
Rel(tracing, web, "Traces requests")
UpdateLayoutConfig($c4ShapeInRow = 3)
Major Components and Services
Core Workflow Services:
- Workflow Engine: Core business logic for workflow execution, state management, and approval routing
- Orchestration Service: Manages state transitions, approval sequences, and workflow lifecycle
- Notification Service: Handles email/SMS notifications to approvers and stakeholders
Infrastructure Services:
- API Gateway: Routes requests, handles authentication, rate limiting, and protocol translation
- Authentication Service: JWT-based authentication with RBAC authorization
- Search Service: Elasticsearch-backed search for workflows and approvals
Data Stores:
- Database Layer: PostgreSQL for structured workflow data, audit logs, and user information
- Caching Layer: Redis for caching frequently accessed workflow states and user data
- Message Broker: Kafka for asynchronous event-driven architecture
External Integrations:
- Payment Gateway: For payment-related approval workflows
- Email Service: For sending notifications to approvers
Traffic Flow and Data Flow
- User Request Flow: End users initiate workflows through Web/Mobile APIs, which authenticate via Auth Service and route to Workflow Engine
- Approval Flow: Workflow Engine triggers orchestration service for state transitions, publishes events to Kafka, and sends notifications
- Search Flow: Search service indexes workflow data for fast querying and filtering
- External Integration: External systems integrate via API gateway for payment approvals or other workflow triggers
- Observability Flow: Metrics and tracing services collect telemetry from all services for monitoring and debugging
4. Service Architecture
Microservices vs. Monolith vs. Modular Monolith Decision
For an Approval Workflow System, we'll adopt a modular monolith approach for the initial phase, with clear service boundaries that can evolve into independent microservices. This decision balances:
- Development velocity: Faster iteration and deployment cycles during early development
- Operational simplicity: Single deployment unit reduces operational complexity
- Scalability path: Clear separation of concerns enables future microservice migration
- Consistency requirements: Complex workflow logic benefits from centralized control
Service Decomposition Strategy
We'll decompose the system into the following core services:
- Workflow Engine Service - Core approval logic, state management, and workflow execution
- Approval Request Service - Request creation, retrieval, and lifecycle management
- User Management Service - User profiles, roles, and permissions
- Notification Service - Email/SMS/Slack notifications and communication
- Audit & Compliance Service - Audit trails, compliance reporting, and policy enforcement
Service Boundaries and Contracts
Each service will maintain clear boundaries with well-defined APIs:
-
Workflow Engine Service:
- REST API for workflow definition, execution, and state transitions
- Events for workflow lifecycle changes (started, completed, rejected)
-
Approval Request Service:
- REST API for request creation, status updates, and retrieval
- Events for request state changes (submitted, approved, declined)
-
User Management Service:
- REST API for user and role management
- Events for role changes or user additions
Inter-Service Communication Pattern
Synchronous (REST/gRPC) for:
- Request-to-Workflow Engine communication
- Real-time status queries from UI
Asynchronous (Events) for:
- Cross-service notifications (e.g., workflow completion triggers audit logging)
- Audit trail updates
- Notification queuing
Service Mesh Consideration
We'll implement Istio as a service mesh for:
- Traffic management and routing
- Security policies (mTLS, rate limiting)
- Observability integration (distributed tracing, metrics)
- Circuit breaker and retry policies
Service Registry and Discovery Strategy
We'll use Consul for service discovery with:
- Health check integration
- Service registration and deregistration
- Configuration management for service-specific settings
- Multi-region support for global availability
Service Design Principles
- Stateless services to enable horizontal scaling
- Idempotent operations for reliable workflow execution
- Event-driven architecture to decouple services and enable real-time updates
- Service isolation with clear data ownership boundaries to prevent cross-service coupling
Future Migration Path
The modular monolith design provides a clear migration path to independent microservices by:
- Establishing well-defined service contracts and data boundaries
- Implementing proper event-driven communication patterns
- Building service-specific databases to avoid shared database dependencies
- Creating independent deployment pipelines and monitoring for each service
This approach ensures we build a maintainable, scalable system while providing flexibility for future architectural evolution.
5. Data Architecture
Database Selection per Service
Approval Workflow Service:
- Primary DB: PostgreSQL (v14+) - Relational model for approval workflows, steps, and state management
- Justification: Strong ACID guarantees, complex query support for approval logic, mature ecosystem, and excellent tooling for audit trails
User Management Service:
- Primary DB: MongoDB (v6+) - Document store for user profiles, roles, and preferences
- Justification: Flexible schema for varying user attributes, geospatial queries for global distribution, and good horizontal scaling capabilities
Audit & Logging Service:
- Primary DB: TimescaleDB (v2+) - Time-series data for audit logs and workflow tracking
- Justification: Optimized for time-series data with efficient compression, built-in partitioning, and analytical query capabilities
Notification Service:
- Primary DB: Redis (v7+) - Key-value store for notification queues and caching
- Justification: Fast in-memory operations, Pub/Sub capabilities for real-time notifications, and simple TTL-based expiration
Data Partitioning Strategy
Approval Workflow Service:
- Partitioning Method: Hash-based sharding on
tenant_id(for multi-tenant support) - Justification: Even distribution of approval workflows across shards, predictable performance scaling, and manageable cross-shard queries through tenant-aware APIs
User Management Service:
- Partitioning Method: Range-based sharding on
user_idhash - Justification: Optimizes read-heavy operations for user profiles, supports efficient range queries for role-based access, and enables horizontal scaling
Data Replication Strategy
Primary-Replica Model:
- Master-Slave Architecture: Primary database with read replicas for read-heavy approval workflow queries
- Cross-Region Replication: Multi-region setup with asynchronous replication for disaster recovery and low-latency reads
Consistency Model:
- Eventual Consistency: For non-critical data (audit logs, user preferences)
- Strong Consistency: For approval state and workflow transitions
Cross-Service Data Ownership
No Shared Databases Rule:
- Each service owns its data exclusively, with cross-service communication through well-defined APIs and events
- Enforcement Strategy:
- Database access controlled via service accounts with minimal privileges
- API gateway enforces service boundaries and data access policies
- Event-driven architecture ensures data consistency without direct database access
CQRS Pattern Application
Approval Workflow Service:
- Command Side: Handles workflow creation, approval/rejection, and state transitions
- Query Side: Separate read models for dashboard views, approval lists, and analytics
- Implementation:
- Command events published to Kafka for eventual consistency
- Read models maintained in separate PostgreSQL schemas for optimized queries
Audit Service:
- Command Side: Audit log creation and retention management
- Query Side: Analytics-ready denormalized tables for compliance reporting
Event Sourcing Consideration
Use Case Analysis:
- Not Applied: Approval workflows are primarily about state transitions rather than historical reconstruction
- Alternative Approach: Event-driven architecture with Kafka for audit trail and state change notifications
Trade-offs:
- Pros: Complete auditability, ability to reconstruct past states, supports complex business logic
- Cons: Increased complexity, higher storage requirements, more challenging debugging and maintenance
Storage Tiering Strategy
Hot Data:
- Approval State: In-memory Redis cache with 30-day TTL for active workflows
- User Profiles: MongoDB primary database (hot reads)
Warm Data:
- Audit Logs: TimescaleDB with 90-day retention for compliance
- Workflow Templates: PostgreSQL with read replicas
Cold Data:
- Archived Workflows: S3 Glacier for long-term storage with metadata in PostgreSQL
- Historical Reports: GCS Archive storage with lifecycle policies
Backup and Restore Strategy
Backup Approach:
- Incremental Backups: Hourly incremental backups with full weekly snapshots
- Cross-Region Replication: Multi-region backup storage for disaster recovery
RTO/RPO Targets:
- RTO: 15 minutes for critical services (approval workflows, user management)
- RPO: 5 minutes maximum for approval state and audit logs
- Restore Testing: Monthly restore drills with full system recovery validation
Backup Storage:
- Primary: Cloud-native storage (AWS S3, GCP Cloud Storage)
- Secondary: Cross-region replication for disaster recovery scenarios
Compliance Considerations:
- Retention Policies: 7 years for audit logs, 3 years for approval history
- Encryption: At-rest encryption with key rotation every 90 days
- Access Controls: Role-based access with audit logging for all backup operations
6. Caching Architecture
Cache Layers and Hierarchy
The approval workflow system will implement a multi-layer caching strategy to optimize read performance and reduce database load:
- Client-side Cache (L1): Browser/local storage for user session data and recently viewed approvals
- CDN Cache (L2): Content delivery network for static approval templates, policy documents, and metadata
- API Gateway Cache (L3): Request-level caching for common approval status queries and user profile data
- Application Cache (L4): In-memory cache (Redis) for workflow state, pending approvals, and approval history
- Database Query Cache (L5): Query result caching at database layer for frequently accessed approval data
In-Memory vs. Distributed Cache Design
L4 - Application Cache (Redis) will be the primary distributed cache layer:
-
Primary Use Cases:
- Workflow state tracking (approval status, current approvers)
- Pending approvals list per user
- Approval history with pagination
- User role and permission caches
-
Cache Strategy:
- Time-based expiration (TTL) with sliding windows for active workflows
- Size limits with LRU eviction policy to prevent memory bloat
- Cache warming during service startup using precomputed approval data
Cache Sizing and Eviction Strategy
Based on system assumptions:
- Peak concurrent users: 10,000
- Average cacheable data per user: 5KB (approval history + roles)
- Target cache hit rate: 85% for read-heavy approval queries
Cache sizing calculation:
- Total cacheable data: 10,000 users × 5KB = 50MB
- Conservative allocation: 100MB (with 2x buffer for hot keys and metadata)
- Redis cluster with 3 nodes, each with 50MB capacity for redundancy
Eviction Policy:
- LRU (Least Recently Used) with configurable TTLs
- Hot keys (frequently accessed workflows) will have extended TTLs
- Cache warming for critical approval workflows
Cache Consistency Strategy
To maintain consistency across distributed services:
-
Cache Invalidation Pattern:
- Write-through pattern for approval state changes
- Cache invalidation on approval completion or rejection
- Event-driven cache updates via message broker (Kafka)
-
Cache Coherency:
- Cache invalidation messages published to approval status change events
- Service mesh integration for cache-aware communication
- Cache consistency checks during read operations (cache miss → DB fetch + cache update)
Cache Warming Strategy
- Startup Warm-up: Load recent approval workflows from database into cache on service boot
- Pre-warming: Warm cache for high-volume approval templates and policy documents during deployment
- Hot Path Pre-warming: Proactively cache workflows with high approval frequency or recent activity
Cache Hit Rate Targets and Performance Impact
Target: 85% cache hit rate for approval status queries
- Impact: Reduces database QPS from 500 to ~75 QPS (85% reduction)
- Latency Improvement: 90th percentile query latency reduced from 200ms to ~30ms
- Database Load: 85% reduction in database connections and query load
Cache Monitoring and Metrics
- Cache Hit/Miss Ratio: Per service and per cache layer
- Cache Latency: Distribution of cache access times (p50, p95, p99)
- Cache Size Metrics: Memory usage and eviction rates
- Error Rate: Cache read/write failures and revalidation errors
Cache Failure Handling
-
Graceful Degradation:
- Fail-soft mode where cache misses fall back to database reads
- Circuit breaker pattern to prevent cascading cache failures
-
Fallback Strategy:
- Read-through caching with database fallback
- Cache warming during service startup to minimize cold starts
Cache Data Partitioning
For multi-tenant approval workflows:
- Tenant-based partitioning: Each tenant's approval data isolated in separate cache keyspace
- Workflow ID hashing: For distributed cache distribution across Redis cluster nodes
- Cache sharding strategy: Consistent hashing to maintain cache locality while enabling horizontal scaling
Cache Performance Optimization
- Batching: Batch multiple approval status queries into single cache fetch operations
- Pre-fetching: Predictive prefetching of upcoming approval workflows based on user behavior patterns
- Cache Compression: Compress frequently accessed approval data structures to reduce memory footprint
This caching architecture balances performance optimization with system reliability, ensuring that the approval workflow system can handle peak loads while maintaining low-latency responses for critical approval operations.
7. Messaging & Event Streaming Architecture
Message Broker Selection
For the approval workflow system, we'll use Apache Kafka as the primary message broker due to:
- High throughput requirements: Approval workflows can generate thousands of events per second during peak hours
- Durability guarantees: Kafka's persistence model ensures approval events are not lost even during system failures
- Scalable partitioning: Horizontal scaling capability to handle growing event volumes
- Stream processing capabilities: Integration with Kafka Streams or KSQL for real-time workflow state updates
- Mature ecosystem: Strong tooling and monitoring support (Confluent Control Center, Kafka Manager)
Event Schema Registry and Versioning
We'll implement the Confluent Schema Registry for:
- Schema evolution management: Controlled backward/forward compatibility for approval workflow events
- Version control: Track schema changes with version numbers and migration paths
- Validation: Ensure all events conform to defined schemas before publishing
- Type safety: Prevent malformed approval request or status update events
Topic Partitioning and Consumer Group Design
Partitioning strategy:
- ApprovalRequestCreated: Hash partitioned by
requestIdfor consistency - ApprovalStatusUpdated: Hash partitioned by
workflowInstanceIdto group related events - UserAssignmentChanged: Hash partitioned by
userIdfor user-centric processing
Consumer groups:
- ApprovalProcessor: Handles approval request processing and state transitions
- NotificationService: Processes events for sending email/SMS notifications
- AuditLogger: Maintains audit trail of all approval actions
- AnalyticsService: Aggregates workflow metrics and performance data
Event Ordering Guarantees
- Per-partition ordering: Events within the same partition maintain strict order
- Global ordering: Not guaranteed for cross-workflow events but acceptable for approval systems where process consistency is more important than global ordering
- Idempotent processing: All consumers implement idempotent event handling to handle duplicates
Exactly-once vs. At-least-once Processing Trade-offs
Decision: At-least-once processing with idempotent consumers for the following reasons:
- Approval system reliability: Critical that all approval actions are processed at least once
- Audit trail integrity: Re-processing ensures complete audit logs even if failures occur
- Simpler implementation: Avoids complexity of maintaining transactional state across services
Implementation approach:
- Use Kafka's built-in idempotent producer configuration
- Implement idempotent consumer logic with state tracking
- Use
groupIdfor consumer group management to handle rebalancing gracefully
Event Replay and Reprocessing Strategy
Replay capability:
- Event retention: 30-day retention policy for approval events to support replay
- Replay API: REST endpoint to trigger reprocessing of specific workflow instances
- Event filtering: Support for time-range and status-based filtering for targeted replay
Reprocessing triggers:
- System failures: Automatic retry with exponential backoff for failed consumers
- Schema updates: Manual trigger to reprocess events after schema changes
- Bug fixes: Targeted replay for specific workflows affected by known issues
Dead Letter Queue and Poison Pill Handling
DLQ strategy:
- Dead letter topic: Dedicated Kafka topic for events that fail processing after max retries
- Retry configuration: Max 3 retries with exponential backoff (1s, 2s, 4s)
- Monitoring: Alerting on DLQ queue size and processing failures
Poison pill handling:
- Failure detection: Identify malformed events or services that consistently fail to process
- Manual intervention: DLQ events can be manually inspected and reprocessed via admin interface
- Error categorization: Classify DLQ events by failure type (validation, service unavailable, etc.)
Monitoring and alerting:
- DLQ queue size: Alert when DLQ exceeds 1000 events
- Processing latency: Monitor for events that take longer than expected to process
- Retry count: Alert when retry count exceeds threshold for individual events
8. Reliability Engineering
Failure Mode Analysis
Single Points of Failure:
- Approval Workflow Engine: Central service handling all approval logic - single point of failure if not properly clustered
- Database Layer: Single PostgreSQL instance or sharded cluster without proper failover
- Message Broker: Kafka/Zookeeper failure affecting all workflow state transitions
- Authentication Service: Identity provider outage preventing any approvals from being processed
- External Integrations: Third-party approval systems (e.g., Slack, email) failure causing workflow stalls
Service-Level Failures:
- Approval State Machine: Deadlock in approval transitions due to race conditions
- Notification Service: Email/SMS delivery failures causing approval timeouts
- Audit Logging: Write failures in audit trail breaking compliance requirements
Fault Tolerance Patterns
Circuit Breaker Strategy:
- Per-External Integration: Circuit breaker per external system (Slack, email, etc.) with 500ms timeout and 30s reset
- Internal Service Calls: Circuit breaker for cross-service calls (approval → notification → audit)
- Retry Logic: Exponential backoff with jitter for transient failures (1s, 2s, 4s, 8s max)
Bulkhead Pattern:
- Queue Isolation: Separate queues for different approval types (expense, access, content)
- Resource Pooling: Dedicated thread pools per approval workflow type
- Rate Limiting: Per-workflow-type rate limiting to prevent queue overflow
Timeout Strategy:
- Request Timeout: 30s for approval processing, 5s for external API calls
- Workflow Timeout: 72 hours default approval window with configurable overrides
- Retry Timeout: 60s total retry window before marking workflow as failed
Multi-Region / Multi-AZ Strategy
Active-Active Architecture:
- Primary Region: Production region with full approval workflow processing
- Secondary Region: Read-only replica for disaster recovery and audit consistency
- Cross-Region Sync: 15-minute sync window for approval state consistency
Data Replication:
- Database: Multi-region PostgreSQL with read replicas in secondary region
- Event Store: Kafka clusters in both regions with cross-region replication
- Cache Layer: Redis cluster with geo-replication capabilities
Chaos Engineering Strategy
GameDay Sessions:
- Monthly: 2-hour GameDay sessions simulating various failure scenarios
- Failure Types: Database outages, network partitions, external service failures, cache misses
Chaos Monkey Scenarios:
- Service Failures: Randomly terminate approval engine pods every 2 hours
- Network Partitioning: Simulate network isolation between services
- Database Failures: Force database connection timeouts and reconnections
Steady-State Hypothesis:
- Approval Processing: Approval workflows continue processing despite partial failures
- Audit Integrity: Audit logs remain consistent across regions and time
- User Experience: Users can still view their approval status even during partial outages
Disaster Recovery Plan
RTO/RPO Targets:
- RTO: 15 minutes for primary approval processing
- RPO: 5 minutes for audit and approval state consistency
- Recovery Time: 2 hours maximum for full region failover
DR Procedures:
- Failover Trigger: Automated detection of primary region failure
- Traffic Redirect: Route all approval traffic to secondary region
- State Synchronization: Sync pending approvals from primary to secondary
- User Communication: Notify users of regional failover via email/SMS
Runbook Design for Top-5 Failure Scenarios
1. Database Outage
1. Alert: Primary database unavailable
2. Failover: Promote read replica to primary
3. Retry: Reschedule pending workflows
4. Monitor: Verify approval processing resumes
5. Documentation: Update incident report with root cause
2. External Service Timeout
1. Alert: Slack/email service timeout
2. Circuit Breaker: Trip external integration circuit
3. Fallback: Use email as fallback for notifications
4. Retry: Retry failed notifications after 5 minutes
5. Monitor: Verify notification delivery success rate
3. Workflow Deadlock
1. Alert: Approval workflow stuck in pending state
2. Manual Intervention: Force state transition via admin API
3. Audit: Log root cause analysis in audit trail
4. Retry: Reschedule workflow for processing
5. Prevention: Update state machine to prevent future deadlocks
4. Cache Miss Storm
1. Alert: Cache hit rate drops below 30%
2. Cache Warmup: Trigger cache warming for popular approval workflows
3. Rate Limiting: Apply rate limiting to reduce cache pressure
4. Monitor: Verify cache hit rate returns to normal levels
5. Optimization: Review cache eviction policy and TTL settings
5. Authentication Service Failure
1. Alert: Identity provider unavailable
2. Fallback Mode: Allow local authentication for admin users
3. Retry: Retry authentication requests after service recovery
4. User Impact: Notify users of temporary access restrictions
5. Recovery: Resume normal authentication once service restored
9. Observability Architecture
Logging Stack
- Structured JSON logging across all services using structured log formats for easy parsing and querying
- Loki as the centralized logging system with Promtail agents on each node for log collection
- Grafana for log visualization and dashboard creation with multi-service log aggregation
- Log retention policy: 90 days for operational logs, 1 year for audit trails
- Log filtering: Exclude sensitive fields (passwords, tokens) and implement log redaction for PII data
Distributed Tracing
- OpenTelemetry as the observability framework with automatic instrumentation for core services
- Jaeger as the tracing backend with sampling rate of 1% for production to balance observability vs. overhead
- Trace context propagation through HTTP headers and message brokers for cross-service tracing
- Critical trace paths: User approval request → approval decision → notification → audit log
- Trace correlation with request IDs for end-to-end visibility
Metrics Stack
- Prometheus as the primary metrics store with 15s scrape interval for critical services
- Grafana for dashboard visualization and alerting configuration
- Service-level metrics: QPS, latency (p50/p95/p99), error rates, throughput, cache hit ratios
- Infrastructure metrics: CPU, memory, disk I/O, network utilization, database connection pool usage
- Business metrics: Approval request volume, approval rate, average approval time, rejection rate
Alerting Strategy
- Severity levels:
- P0: Service unavailability, critical data loss (PagerDuty escalation)
- P1: High latency (>500ms p99), high error rates (>5%)
- P2: Medium latency, moderate error rates
- P3: Minor performance degradation, non-critical alerts (OpsGenie)
- Alerting rules:
- Service health checks every 30s
- Error rate thresholds (5xx errors > 1%)
- Latency thresholds (p99 > 1s)
- Queue depth warnings for approval workflow queues
- Notification routing:
- Critical alerts to on-call engineers via PagerDuty
- Non-critical alerts to team Slack channels
SLI/SLO Definition and Error Budget Tracking
- SLIs:
- Request success rate (99.5% SLO)
- Approval processing latency (<2s p99)
- System availability (99.9% SLO)
- SLOs:
- Approval workflow completion within 5 seconds (p99) - 99.9% SLO
- System uptime > 99.9% (24h/month downtime max)
- Audit trail completeness - 100% SLO
- Error budget:
- 0.1% error budget for approval processing latency
- Allow 24h of error budget per month before alerting
- Dashboard:
- Error budget burn rate visualization
- Service health status cards
- SLI/SLO compliance metrics
Capacity Planning and Load Forecasting
- Historical trend analysis:
- Monthly approval request volume trends
- Peak hour patterns and seasonal variations
- Load forecasting model:
- Time-series forecasting using Prophet or ARIMA for approval volume prediction
- Forecasting accuracy target: ±15% for next 30 days
- Capacity alerting:
- Auto-scaling triggers based on projected load
- Resource utilization thresholds (CPU >85%, memory >80%)
- Capacity planning dashboard:
- Resource utilization trends
- Forecast vs actual approval volume comparison
- Service scaling recommendations
10. API Gateway & Edge Layer
API Gateway Selection
For an Approval Workflow System, I recommend AWS API Gateway as the primary API gateway solution with the following justification:
- Managed service benefits: Reduces operational overhead and provides built-in security features
- Native AWS integration: Seamless integration with Lambda, Cognito, and other AWS services
- Rate limiting and throttling: Built-in rate limiting with per-user and global limits
- Request/response transformation: Supports content-based routing and payload transformations
- Monitoring and logging: Native integration with CloudWatch and X-Ray for observability
Alternative consideration: Kong if the system requires extensive customization or multi-cloud deployment.
Request Routing Strategy
The API gateway will implement a multi-tier routing strategy:
- Path-based routing:
/approvals/{id},/workflows,/users,/notifications - Content-based routing: Route based on request headers (e.g.,
Accept: application/json) - Service-specific endpoints:
/api/v1/approvals→ Approval Service/api/v1/workflows→ Workflow Service/api/v1/users→ User Management Service
Authentication and Authorization
Authentication Flow:
- OAuth2 with JWT tokens: Integration with AWS Cognito or Auth0 for user authentication
- Service-to-service mTLS: For inter-service communication using AWS IAM roles or custom certificates
Authorization:
- Role-based access control (RBAC): Users assigned to roles (Approver, Admin, Requester)
- Policy enforcement: JWT claims validated for required permissions
- Request context enrichment: User roles and permissions added to request context before forwarding
Rate Limiting and Throttling Design
Global Rate Limits:
- 1000 RPS per user for approval operations
- 5000 RPS per user for read operations (workflows, history)
- 10000 RPS global limit for system management endpoints
Per-Client Limits:
- Application-level rate limiting using API keys
- Client-specific quotas for enterprise customers
Request Transformation and Protocol Translation
Request Transformations:
- Content-type handling: JSON to XML conversion for legacy systems
- Field mapping: Normalize field names across different client integrations
- Payload validation: Schema validation before forwarding to services
Protocol Translation:
- Support for both REST and GraphQL endpoints
- HTTP/2 support for improved performance
- WebSocket support for real-time approval notifications
BFF (Backend for Frontend) Design
Frontend-Specific Considerations:
- Aggregation layer: Combine multiple service responses for dashboard views
- Client-specific optimizations:
- Mobile-optimized responses with reduced payload size
- Pre-computed approval status for frequently accessed workflows
- Caching strategy: Client-specific cache invalidation based on user activity
BFF Services:
approval-dashboard-bff: Aggregates approval status, workflow history, and notificationsworkflow-editor-bff: Provides optimized views for creating and modifying workflowsuser-profile-bff: Consolidates user preferences, permissions, and team memberships
Edge Layer Considerations
CDN Integration:
- Static assets (UI components, documentation) served through CloudFront
- Caching strategy for frequently accessed workflow templates and approval forms
Edge Computing:
- Pre-processing of simple requests at edge locations for reduced latency
- Caching of frequently accessed approval metadata (status, types, templates)
Security at Edge:
- DDoS protection through AWS Shield Advanced
- WAF rules for common attack patterns (SQL injection, XSS)
- Request size limiting to prevent resource exhaustion
Performance Characteristics
Latency Targets:
- p50: < 100ms for simple approval requests
- p95: < 300ms for complex workflow operations
- p99: < 1s for dashboard aggregations
Throughput Requirements:
- 5000 RPS average for approval operations
- 10,000 RPS peak during business hours (8-6 PM)
- Support for 100 concurrent users with real-time notifications
Integration Points
External Integrations:
- Notification services: SMS, email, Slack integration through API Gateway
- Identity providers: SAML/SSO integration for enterprise customers
- Third-party approval systems: Integration with external approval platforms via webhook endpoints
Internal Service Integration:
- Workflow engine: Direct integration with workflow execution services
- Notification service: Event-driven notifications through API Gateway endpoints
- Audit logging: Centralized logging through API Gateway request/response capture
Monitoring and Observability
Gateway-level metrics:
- Request count, latency, error rates per endpoint
- Rate limiting violations and throttling events
- Authentication success/failure rates
Tracing integration:
- Distributed tracing through X-Ray for end-to-end request flow
- Request correlation IDs for debugging approval workflows
Scalability Considerations
Horizontal scaling:
- API Gateway instances automatically scale with traffic
- Multi-AZ deployment for high availability
- Regional deployment to minimize latency for global users
State management:
- Stateless design with all session data stored in Redis or DynamoDB
- Session affinity not required due to stateless architecture
Security and Compliance
TLS/SSL requirements:
- All endpoints must use TLS 1.3 or higher
- Certificate management through AWS ACM for automated renewal
Compliance considerations:
- GDPR compliance for data handling and user consent
- HIPAA compliance if handling healthcare-related approvals
- SOC2 Type II compliance for enterprise customers
Future Extensibility
Extensible design:
- Plugin architecture for custom authentication methods
- Support for new protocols and content types
- Modular design allowing addition of new edge services without gateway changes
This API Gateway design provides a robust, scalable, and secure foundation for the Approval Workflow System while maintaining flexibility for future enhancements and integrations.
11. Authentication & Authorization Architecture
Identity Provider Integration
For an approval workflow system, we'll integrate with AWS Cognito as the identity provider due to its seamless integration with AWS services, built-in support for SAML/OIDC, and robust user pool management capabilities. Cognito provides federated identity through social providers (Google, GitHub) and enterprise SSO via SAML 2.0, which is crucial for enterprise adoption.
OAuth2 / OIDC Flow Design
sequenceDiagram
participant U as User
participant IdP as Identity Provider (Cognito)
participant AuthS as Approval Auth Service
participant API as Approval API Gateway
U->>IdP: Request login with OIDC
IdP->>U: Redirect to IdP login page
U->>IdP: Authenticate and consent
IdP->>AuthS: Redirect with ID token + refresh token
AuthS->>IdP: Validate token
AuthS->>API: Forward validated claims and refresh tokens
API->>U: Return access token for API calls
The system uses the Authorization Code flow with PKCE for web applications, ensuring secure token handling and preventing CSRF attacks. Tokens are short-lived (15-30 minutes) with refresh tokens for seamless re-authentication.
Service-to-Service Authentication
For inter-service communication, we'll implement mTLS using Istio service mesh with SPIFFE/SPIRE for identity management. This ensures that all internal communications are authenticated and encrypted, preventing unauthorized service access.
RBAC / ABAC Model Design
We'll implement a hybrid RBAC/ABAC model:
Role-Based Access Control (RBAC)
- Predefined roles:
Approver,Requester,Admin,Auditor - Role hierarchy: Admin > Approver > Requester, with inheritance
- Roles mapped to permissions via policy documents
Attribute-Based Access Control (ABAC)
- Context-aware permissions for approval workflows:
- Approval limits based on user's department/role hierarchy
- Budget constraints for specific approval levels
- Time-based access (e.g., approvals only during business hours)
- Geographic location restrictions
The hybrid model allows for flexible policy enforcement while maintaining clear role boundaries.
Token Revocation Strategy
We'll implement a multi-layered token revocation system:
- Short-lived JWT tokens (15-30 min) with refresh token rotation
- Blacklist-based revocation for immediate logout or session termination
- Refresh token validation with database state tracking to invalidate tokens when needed
When a user logs out or is deactivated, their refresh tokens are invalidated in the database and added to a revocation list. The system checks this list during token refresh operations to prevent reuse.
Token Storage and Security
Access tokens are stored in secure HTTP-only cookies with SameSite=Strict to prevent XSS attacks. Refresh tokens are stored in secure, HTTP-only cookies with Secure=true and SameSite=Lax for cross-site request protection.
Session Management
Session state is maintained server-side in Redis with TTLs matching token expiration. Sessions are invalidated immediately upon logout or token revocation, with automatic cleanup through Redis's built-in TTL expiration.
Authentication Flow Summary
- User authentication via Cognito OIDC flow
- Token validation and user claim extraction
- Role assignment based on Cognito groups or custom claims
- ABAC policy evaluation for context-dependent permissions
- Secure service-to-service communication via mTLS + SPIFFE identity
- Token refresh with revocation validation
- Session cleanup on logout or token invalidation
This architecture provides enterprise-grade security with flexible authorization policies that can adapt to complex approval workflows while maintaining compliance with security best practices.
12. Search Architecture
Search Use Cases and Requirements
The approval workflow system requires robust search capabilities for:
- Approval request discovery: Users need to quickly find pending approvals by owner, status, or type
- Audit trail search: Compliance and audit teams must search through historical approval records
- Metadata-based filtering: Search by request type, approver group, creation date ranges, and approval status
- Full-text search: Searching through request descriptions, comments, and metadata fields
Search Indexing Pipeline
The search system follows a multi-stage indexing pipeline:
- Source: Approval request events from the workflow engine and approval state changes
- Transform: Enrichment of approval metadata, user role mapping, and status normalization
- Index: Real-time indexing into search backend with field-level configuration
Index Schema and Query Patterns
Core indexed fields:
request_id(primary key)owner_user_id(for user-specific queries)approval_type(category for filtering)status(approval state)created_at(time-based queries)updated_at(audit trail)approver_user_ids(multi-value for group queries)request_metadata(full-text searchable JSON field)
Query patterns:
- User dashboard queries:
owner_user_id+status+created_atrange - Admin audit queries:
approval_type+status+updated_atrange - Group approval queries:
approver_user_ids+status
Real-time vs. Near-real-time Indexing
Real-time indexing strategy:
- Critical for user-facing dashboard queries where users expect immediate visibility of new approvals
- Implemented using Kafka-based streaming pipeline with Elasticsearch as the search backend
- Indexing delay target: < 500ms for new approval creation events
Near-real-time indexing for audit queries:
- Historical search can tolerate up to 5-minute delay for cost optimization
- Batch indexing job runs every 5 minutes for older approval records
Relevance Tuning Strategy
Search ranking factors:
- Temporal relevance: Recent approvals rank higher in user dashboards
- Status urgency: Pending approvals with approaching deadlines receive higher weight
- User role relevance: Approvals assigned to the current user or their teams get boosted
Query boosting configuration:
status:pending→ +20 pointsowner_user_id:{current_user}→ +15 pointsapprover_user_ids:{current_user}→ +10 pointscreated_atwithin last 24h → +5 points
Search Scaling Design
Sharding strategy:
- Horizontal sharding by
approval_typeto distribute load across search clusters - Each approval type gets dedicated shards for better query performance isolation
Replica configuration:
- 3 replicas per shard for high availability (99.9% SLA)
- Cross-zone replication to ensure fault tolerance
Index lifecycle management:
- 30-day retention for active approval records
- Archival of historical approvals to cold storage with reduced search capability
Search Performance Targets
Query latency targets:
- p50: < 100ms for dashboard queries
- p95: < 300ms for audit queries
- p99: < 1s for complex multi-facet searches
Throughput targets:
- 5000 QPS for user dashboard searches
- 2000 QPS for audit and admin search queries
Search Integration with Approval System
Search API endpoints:
GET /approvals/search- User dashboard search with filters and paginationGET /approvals/audit- Admin audit trail search with full-text capabilities
Search result enrichment:
- Search responses include minimal approval metadata for direct UI rendering
- Full approval details fetched via separate API calls to reduce search payload size
Search state synchronization:
- Search index updates synchronized with database state changes using event-driven architecture
- Consistency guarantees through eventual consistency model with conflict resolution for concurrent updates
13. Scalability Deep Dive
Bottleneck Identification
User Load Analysis:
- Peak QPS: 100,000 (10x average of 10,000)
- Concurrent approval requests: ~5,000 (assuming 50ms average processing time)
- Peak database QPS: ~20,000 (after cache hit rate of 95%)
- Storage growth: 1GB/user/year (assuming 100 approvals/user with 10KB each)
Critical Path Bottlenecks:
- Database contention: Approval state transitions and concurrent writes to approval records
- Workflow engine concurrency: Processing multiple approvals simultaneously in same workflow
- Notification service: Email/SMS burst during approval processing
- Cache invalidation: High cache invalidation rate during approval state changes
Horizontal vs Vertical Scaling Decisions
Stateless Services (API Gateway, Approval Service):
- Horizontal scaling: Enabled via Kubernetes deployments with HPA
- Vertical scaling: Minimal - services designed to be stateless and lightweight
- Scaling factor: 2x peak capacity (100k QPS → 200k capacity)
Stateful Services (Workflow Engine, Approval DB):
- Horizontal scaling: Limited due to workflow state consistency requirements
- Vertical scaling: Enabled via database connection pooling and read replicas
- Scaling factor: 3x peak capacity for workflow engine (10k concurrent approvals → 30k)
Database Scaling Path
Phase 1: Single Master
- 1x PostgreSQL master with read replicas (25% of write load)
- Cache layer reduces DB QPS by 95% (20k → 1k)
Phase 2: Read Replicas + Connection Pooling
- 3x read replicas for reporting and read-heavy workflows
- Connection pooling reduces DB connection overhead by 70%
- Peak QPS: 1,500 (after cache and read replicas)
Phase 3: Sharding Strategy
- Horizontal sharding by approval workflow type (user approvals, document approvals)
- Each shard handles 500 concurrent workflows
- Cross-shard approval tracking via central metadata store
Phase 4: Distributed DB
- Migration to CockroachDB or Spanner for global consistency
- Eliminates cross-shard coordination overhead
Stateless vs Stateful Service Design Implications
Stateless Services:
- Benefits: Easy to scale, no session affinity required, can be load balanced freely
- Implementation: API gateway, approval request handlers, notification service
- Scaling: Can scale horizontally to any capacity with proper load balancing
Stateful Services:
- Challenges: Session affinity, state synchronization, consistency across instances
- Implementation: Workflow engine, approval decision engine (must maintain workflow state)
- Scaling: Requires careful state management and coordination
Session Affinity and Its Implications
Workflow Engine:
- No session affinity required: Workflow state is stored in database, not in-memory
- Consistent processing: Same workflow can be processed by any instance
- Implication: Stateless design allows for better distribution of load
Approval Processing:
- No session affinity: Approval state transitions are atomic and idempotent
- Parallel processing: Multiple instances can process different approvals simultaneously
- Implication: High availability and fault tolerance
Scalability Metrics and Triggers
Database Scaling Triggers:
- DB CPU > 80% for 5 minutes → scale read replicas
- Connection pool exhaustion → scale database instances
- Query latency > 500ms → enable read replicas or query optimization
Service Scaling Triggers:
- QPS > 80% of capacity → auto-scale up
- Memory usage > 85% → scale up or optimize memory usage
- Latency > 200ms (p95) → investigate and optimize
Cache Scaling Triggers:
- Cache hit rate < 90% → increase cache size or optimize cache keys
- Cache eviction rate > 1000/sec → consider cache warming strategy
Performance Optimization Strategies
Database Query Optimization:
- Indexes on approval workflow type, status, and timestamp
- Batch processing for approval state updates (50 at a time)
- Materialized views for common approval reports
Service-Level Optimizations:
- Async approval decision processing to prevent blocking
- Bulk operations for approval state updates (batching)
- Pre-warming of frequently accessed workflows in cache
Infrastructure-Level Optimizations:
- Kubernetes HPA with custom metrics (QPS, DB latency)
- Resource quotas and limits to prevent resource exhaustion
- Auto-scaling groups with proper warm-up periods
Capacity Planning Considerations
Peak Load Projections:
- 100k QPS peak (10x average) requires 2x capacity for redundancy
- 5,000 concurrent approvals require 3x capacity for workflow engine
- 1GB/user/year storage growth requires 50TB/year capacity planning
Resource Utilization Targets:
- CPU utilization < 70% for all services
- Memory usage < 80% for stateless services
- Database CPU < 60% for optimal performance
- Cache hit rate > 95% to minimize database load
Horizontal Scaling Benefits:
- Linear scaling capability with Kubernetes deployments
- Improved fault tolerance and availability
- Better resource utilization through efficient load distribution
This scalability design ensures the system can handle 10x growth in user base and approval volume while maintaining consistent performance and availability. The architecture is designed to be highly elastic, with proper monitoring and alerting to trigger scaling actions automatically.
14. Infrastructure & Deployment Architecture
Cloud Provider and Region Selection
For a global approval workflow system, we'll target AWS as the primary cloud provider due to its mature ecosystem of managed services, extensive global infrastructure, and strong compliance offerings. The system will be deployed across multiple regions (us-east-1, us-west-2, eu-west-1) to support active-active multi-region architecture for high availability and disaster recovery.
Kubernetes Cluster Design
We'll implement a multi-tenant Kubernetes cluster model with dedicated namespaces for each service and environment (dev, staging, prod). Each namespace will have:
- Resource quotas to prevent resource contention
- Network policies for service-to-service communication control
- Pod security policies enforcing least privilege access
Cluster configuration includes:
- Control plane in multi-AZ setup for HA
- Worker nodes in separate AZs with auto-scaling groups
- Node taints and tolerations to isolate critical workloads
Container Image Strategy
All services will use multi-stage Docker builds:
- Build stage: Using official language-specific base images with build tools
- Runtime stage: Minimal Alpine or Debian-based images with only necessary runtime dependencies
- Image registry: AWS ECR for global distribution and integration with CI/CD pipelines
Deployment Strategy
We'll implement a hybrid deployment approach:
- Production: Blue-green deployments with traffic shifting via API Gateway
- Staging: Canary releases with gradual traffic shift (10% → 50% → 100%) using Istio for traffic management
- Development: Rolling updates with rollback capability
Deployment automation includes:
- GitOps approach using ArgoCD for declarative infrastructure and application management
- Automated testing (unit, integration, E2E) in pre-deployment validation pipeline
- Rollback triggers based on error rate and latency thresholds
Auto-scaling Design
Horizontal Pod Autoscaling (HPA) will be implemented for:
- CPU utilization thresholds (70% target)
- Custom metrics from Prometheus for business-specific scaling signals
- External metrics for queue depth and message processing rates
Vertical Pod Autoscaling (VPA) will be used for:
- Memory optimization based on historical usage patterns
- CPU allocation adjustments to prevent resource starvation
KEDA will be integrated for:
- Event-driven scaling of approval processing services based on queue depth
- Auto-scaling of background workers for workflow engine tasks
Infrastructure as Code Approach
Infrastructure will be managed using:
- Terraform for infrastructure provisioning (VPC, subnets, security groups, RDS instances)
- Helm for Kubernetes chart management with versioned releases
- Terragrunt for environment-specific configuration and module organization
- GitHub Actions for CI/CD pipeline automation with drift detection and compliance checks
All infrastructure changes will follow a pull request review process with automated validation using:
- Terraform fmt and validate checks
- Security scanning with tfsec and checkov
- Compliance validation against AWS security baseline standards
The infrastructure will support:
- Multi-account strategy (dev, staging, prod) with cross-account role assumptions
- Centralized logging and monitoring integration
- Automated security group rule validation and compliance checks
- Infrastructure cost tracking through tagging and cost allocation tags
15. Security Architecture
VPC Design and Network Segmentation
The system will operate within a multi-AZ VPC architecture with strict network segmentation. Public subnets will host API gateways and load balancers, while private subnets will contain all backend services and databases. Each service will reside in its own isolated subnet with security groups enforcing strict ingress/egress rules. Cross-service communication will be restricted to internal VPC endpoints only, with no direct internet exposure.
Zero-Trust Network Model
All service-to-service communication will implement zero-trust principles with mutual TLS (mTLS) for all internal network traffic. Network policies will enforce strict access control lists (ACLs) at the VPC level, ensuring that services can only communicate with explicitly authorized components. All external API calls will be routed through a centralized service mesh for consistent security policy enforcement.
TLS Termination Strategy
TLS termination will occur at the API gateway level with mTLS enabled for service-to-service communication. All external traffic will terminate at the load balancer with strong cipher suites (TLS 1.3+), while internal service communication will maintain end-to-end encryption using mTLS with certificate rotation every 90 days.
DDoS Protection Strategy
AWS Shield Advanced will be enabled for all public-facing endpoints to provide automatic DDoS protection with real-time traffic filtering. Rate limiting will be implemented at the API gateway level to prevent abuse, with automatic blocking of suspicious traffic patterns. CloudFront integration will provide additional DDoS protection for static content and API endpoints.
Secrets Management Architecture
Secrets will be managed through AWS Secrets Manager with automatic rotation every 90 days. Service accounts and database credentials will be rotated programmatically using AWS Lambda functions. Secrets will be encrypted at rest with KMS and accessed only through secure IAM roles with least-privilege permissions. No secrets will be stored in code repositories or configuration files.
Vulnerability Scanning in CI/CD
All container images will undergo automated vulnerability scanning during the build pipeline using Trivy and Snyk. Security scans will be integrated into the CI/CD process with automated blocking of images containing critical vulnerabilities. Container image baselines will be maintained from secure, audited sources with regular security patching.
WAF Rules for Critical Endpoints
AWS WAF will be configured with custom rules to protect critical approval workflow endpoints. Rules will include protection against SQL injection, XSS attacks, and rate limiting for API endpoints. Custom rule sets will be maintained to block known malicious patterns and IP addresses with suspicious behavior.
Security Compliance Framework
The system will implement security controls aligned with SOC2 Type II and GDPR compliance requirements. All data handling will follow privacy-by-design principles with encryption at rest and in transit. Audit logs will be maintained for all approval actions with retention policies meeting regulatory requirements.
Data Protection Controls
All sensitive data will be encrypted using AES-256 encryption at rest with KMS key management. Data in transit will be protected using TLS 1.3+ with forward secrecy. Access to sensitive approval data will be controlled through RBAC and ABAC policies with audit logging for all access patterns.
16. Deployment & Release Strategy
Deployment Strategy
The system will utilize a blue-green deployment strategy for zero-downtime releases, with traffic gradually shifted from the old version to the new version using weighted routing. This approach provides immediate rollback capability if issues are detected within the first few hours of deployment.
For database migrations, a rolling migration approach will be implemented where schema changes are applied incrementally to minimize downtime and ensure data consistency. The migration process will be orchestrated through a dedicated migration service that handles schema evolution, data transformation, and validation checks.
Artifact Promotion Model
The deployment pipeline follows a trunk-based development model with feature branches merged into main after code review. Artifacts are promoted through the following stages:
- Dev Environment: Automated testing and integration with development databases
- Staging Environment: Full end-to-end testing including load testing and security scans
- Production Environment: Blue-green deployment with 20% traffic shift for initial validation, followed by full promotion
Each environment has independent CI/CD pipelines with automated gates that enforce:
- Unit test coverage (minimum 80%)
- Integration test success
- Security vulnerability scans
- Performance benchmarks (p95 latency < 200ms)
Zero-Downtime Database Migration
Database schema migrations will be handled through a migration service that:
- Uses database transactional DDL where supported (PostgreSQL, MySQL 8.0+)
- Implements schema versioning with migration history tracking
- Supports rollback to previous schema versions via versioned migration files
- Applies migrations in a controlled sequence with dependency management
- Performs data transformation in batches to avoid long-running transactions
Feature Flag Integration
Feature flags will be integrated using LaunchDarkly for:
- Progressive rollouts with configurable traffic weights
- A/B testing capabilities for approval workflow variations
- Emergency feature toggles for system maintenance or security patches
The flagging system will support:
- User-based targeting (by department, role, or team)
- Gradual rollouts with automatic traffic shifting
- Real-time flag updates without service restarts
Canary Analysis Automation
Canary deployments will include:
- Traffic Splitting: 5% initial traffic to new version with automatic scaling
- Automated Health Checks: Response time, error rate, and throughput monitoring
- Auto-Rollback Triggers: If p95 latency exceeds 300ms or error rate > 2% for 5 minutes
- Performance Baseline Comparison: Pre-deployment performance benchmarks vs. post-deployment metrics
Release Cadence and Branching Strategy
The system will follow a trunk-based development approach with:
- Daily builds for the main branch
- Release trains every two weeks for production deployments
- Hotfix branches for critical security patches or production bugs
- Feature branches with short lifecycle (max 2 weeks) and mandatory code review
Release windows will be scheduled during low-traffic periods (UTC 02:00-06:00) to minimize impact on users.
Rollback Strategy
In case of deployment failure:
- Immediate traffic shift back to previous stable version
- Automated alerting to on-call engineers with failure details
- Database rollback using migration history and backup restore
- Feature flag reset to disable new functionality
- Post-mortem analysis within 24 hours with root cause identification and mitigation plan
The rollback process will be automated but require manual approval for production environments to prevent accidental rollbacks during maintenance windows.
17. Cost Architecture
Major Cost Drivers Analysis
Compute Costs (35-40% of total): Primarily driven by Kubernetes cluster resources, API gateway instances, and stateful services. CPU-intensive approval routing logic and workflow engine processing contribute significantly to this cost.
Storage Costs (25-30% of total): Mainly from database storage (PostgreSQL/MySQL), event streams (Kafka), and object storage for approval documents. The system stores extensive audit trails and document metadata.
Network & Data Transfer (20-25% of total): Cross-region data replication, API gateway egress traffic, and inter-service communication costs. High-volume approval workflows amplify these costs.
Database & Caching (15-20% of total): Read replicas, Redis clusters, and connection pooling for high availability. The system requires substantial database resources to support concurrent approval workflows.
Cost Optimization Strategy per Layer
Compute Optimization:
- Implement auto-scaling with HPA and VPA to reduce idle resource costs
- Use spot instances for non-critical services where availability isn't impacted
- Implement multi-zone deployment to reduce cross-zone network costs
Storage Optimization:
- Tier storage based on access frequency (hot/warm/cold)
- Implement database query optimization to reduce I/O costs
- Use compression for document storage and event payloads
Network Optimization:
- Deploy services in same region to minimize cross-region data transfer costs
- Implement CDN for static assets and reduce API gateway egress costs
- Use connection pooling to reduce TCP overhead
Reserved vs. Spot Instance Strategy
Reserved Instances:
- Apply to critical services (approval engine, workflow manager) for predictable workloads
- 3-year reserved instances for stable compute requirements
Spot Instances:
- Use for non-critical services (caching layer, background processing)
- Acceptable for batch approval processing and non-time-sensitive workflows
Data Egress Cost Minimization
Cross-Region Replication:
- Implement read replicas in same region to minimize cross-region egress
- Use local caching for frequently accessed approval data
API Gateway Optimization:
- Implement request/response compression to reduce bandwidth usage
- Use efficient JSON serialization to minimize payload sizes
FinOps Dashboards and Budget Alerts
Cost Monitoring Dashboard:
- Real-time cost allocation by service, team, and environment
- Monthly spend trend analysis with forecasting capabilities
- Cost anomaly detection for immediate intervention
Budget Alerting:
- Set up budget alerts at 75%, 90%, and 100% thresholds
- Implement automated cost optimization recommendations when thresholds exceeded
- Weekly cost reports with root cause analysis for overages
Resource Utilization Tracking:
- Monitor CPU and memory utilization to identify under-provisioned resources
- Track database query performance to optimize expensive operations
- Monitor event stream throughput to adjust partitioning and retention policies
The cost architecture is designed to provide visibility into spending while maintaining operational efficiency through intelligent resource allocation and optimization strategies.
18. Open Questions, Risks & Trade-offs
Decisions requiring product / engineering alignment
- Approval hierarchy complexity: How many levels of approval should we support? Should we support parallel approvals or sequential only?
- Approval policy configuration: Should approval rules be configurable by business units or standardized across the organization?
- Notification preferences: What channels should users receive notifications (email, in-app, SMS)? Should these be customizable per user or role?
- Approval timeout behavior: What happens when an approval times out? Should it auto-approve, auto-reject, or escalate to a manager?
- Approval history retention: How long should approval histories be retained? What's the compliance requirement for audit trails?
Key architectural risks
| Risk | Impact | Likelihood | Mitigation |
|---|---|---|---|
| Approval loop due to circular dependencies | High - System could get stuck in infinite approval cycles | Medium - Could occur with complex organizational structures | Implement cycle detection in workflow engine and manual override capability |
| Data consistency during concurrent approvals | High - Risk of duplicate approvals or lost updates | Medium - Concurrent approval operations | Use distributed locks and optimistic concurrency control |
| Audit trail integrity | High - Compliance and regulatory risk | Low-Medium - Could be exploited if not properly secured | Implement immutable audit logs with digital signatures |
| Service availability impact on business workflows | High - Business operations could halt if system unavailable | Medium - Single point of failure risk | Implement circuit breaker and fallback mechanisms |
| Cache invalidation timing issues | Medium - Risk of stale approval states | Medium - Complex state transitions | Implement cache invalidation with event-driven updates |
Trade-offs made with justification
- Consistency vs. availability: Chose eventual consistency for approval state updates to ensure high availability, with strong consistency enforced at critical decision points (approval/rejection) via distributed consensus protocols.
- Flexibility vs. complexity: Prioritized flexible approval workflows over rigid templates to support diverse business use cases, accepting increased system complexity and configuration overhead.
- Real-time vs. batch processing: Used real-time approval handling for critical workflows but implemented batch processing for non-critical notifications to reduce system load and improve throughput.
- Monolithic vs. microservices: Chose a service-oriented approach for approval workflows to enable independent scaling and deployment, despite increased inter-service communication complexity.
- User experience vs. system security: Prioritized user-friendly approval interfaces over overly restrictive security controls, implementing layered security (multi-factor auth, session management) rather than single-point authentication.
Alternatives considered and rejected
- Pre-built workflow engines: Rejected Camunda/Activiti due to high licensing costs and complexity for our use case, preferring custom-built solution for better control and cost optimization.
- Simple state machine: Rejected simple finite state machine approach due to inability to handle complex approval hierarchies and conditional logic required for enterprise use cases.
- Centralized approval service: Rejected single centralized approval service due to scalability limitations and single point of failure risks, opting for distributed workflow engine instead.
- Hardcoded approval rules: Rejected hardcoded business logic in favor of configurable approval policies to support diverse organizational structures and reduce code changes.
Technical debt acknowledged
- Approval policy DSL complexity: Custom domain-specific language for approval rules introduces maintenance overhead and requires extensive documentation.
- Eventual consistency handling: Implementation of eventual consistency patterns across services introduces complexity in debugging and state reconciliation.
- Cross-service audit logging: Manual implementation of cross-service audit trail tracking increases code duplication and maintenance burden.
- Workflow engine extensibility: Custom workflow engine design introduces technical debt in maintaining and extending functionality without proper abstraction layers.
- Notification service coupling: Tight coupling between approval workflow and notification services creates challenges for independent scaling and maintenance.
19. Phased Implementation Roadmap
Phase 1: MVP (Minimum Viable Product)
Timeline: 8-12 weeks
Core Focus: Build foundational approval workflow engine with basic routing and state management
Deliverables:
- Approval request creation and submission API
- Basic approval routing logic (single-level approval)
- Simple approval state machine with PENDING, APPROVED, REJECTED states
- Basic user assignment and notification system (email/SMS)
- Read-only dashboard for approvers to view pending requests
- Core database schema for workflows, approvals, and users
Dependencies:
- Authentication & Authorization system (Phase 2)
- Basic API Gateway and edge layer (Phase 2)
- Core messaging system (Phase 2)
Phase 2: Scale & Enhance
Timeline: 12-16 weeks
Core Focus: Add multi-level approval workflows, rich user experience, and robust infrastructure
Deliverables:
- Multi-level approval workflow support (parallel, sequential, conditional)
- Rich UI dashboard for request creators and approvers
- Advanced notification system (webhooks, in-app, push)
- Workflow templates and configuration UI
- Enhanced state management with history tracking
- Service-to-service authentication (mTLS)
- Integration with external identity providers (Auth0/Okta)
Dependencies:
- Caching architecture (Phase 3)
- Messaging system (Phase 2)
- Observability stack (Phase 3)
- Reliability patterns (Phase 2)
Phase 3: Excellence & Optimization
Timeline: 16-20 weeks
Core Focus: Reliability, performance, and enterprise-grade features
Deliverables:
- Multi-region deployment strategy with active-active support
- Advanced search and filtering capabilities for workflows
- Audit trail and compliance reporting features
- Feature flag integration for progressive rollouts
- Chaos engineering integration (GameDays)
- Advanced caching strategies with warm-up procedures
- Comprehensive observability and alerting system
- Cost optimization and FinOps dashboard integration
Dependencies:
- Full observability stack (Phase 3)
- Advanced caching architecture (Phase 3)
- Multi-region infrastructure (Phase 4)
- Security enhancements (Phase 4)
Critical Path Dependencies:
- Authentication & Authorization - Blocks all user-facing features
- Messaging System - Enables asynchronous workflow processing
- API Gateway & Edge Layer - Critical for request routing and security
- Database Schema - Foundation for all data operations
- Observability Stack - Required for production monitoring and debugging
Milestones:
- Week 12: MVP functional end-to-end approval workflow
- Week 20: Phase 2 features fully implemented and tested
- Week 30: Phase 3 enterprise-grade features deployed
- Week 36: Production-ready with full observability and reliability
Risk Mitigation:
- Technical Debt: Allocate 10% of each phase for refactoring and optimization
- Performance Bottlenecks: Implement load testing in Phase 2
- Scalability Issues: Design horizontal scaling patterns from MVP
- Security Gaps: Integrate security reviews at each phase boundary
- User Adoption: Include feedback loops and iterative UI improvements throughout all phases
Success Metrics:
- 95% of approval requests processed within SLA (5s p95)
- 99.9% availability for core approval workflows
- <100ms response time for dashboard queries
- Zero data loss in approval history (RPO: 0)
- <5% error rate in workflow processing
- 90% user adoption rate within first quarter of launch