Skip to content

fix: resolve nightly analytics failure and optimize database connections#31

Merged
ad-altun merged 3 commits intomainfrom
fix/scaling-and-db-connection-optimization
Jan 21, 2026
Merged

fix: resolve nightly analytics failure and optimize database connections#31
ad-altun merged 3 commits intomainfrom
fix/scaling-and-db-connection-optimization

Conversation

@ad-altun
Copy link
Owner

Summary

  • Fix daily aggregation scheduler that was failing at midnight (container scaled to 0)
  • Optimize database connection pool to reduce page load latency
  • Simplify container scaling to cron-only rules

Problem

  1. Nightly analytics not running: The daily aggregation job was scheduled at midnight, but containers scale to 0 outside working hours (6:55 AM - 5:00 PM)
  2. Slow page loads (7-10s): Azure PostgreSQL was dropping idle connections, causing reconnection delays on first request
  3. Complex scaling rules: EventHub and HTTP scaling rules were ineffective with current configuration

Changes

Scheduler Alignment

  • Move daily aggregation from 00:00 to 07:00 (Europe/Berlin)
  • Ensures container is active when scheduler runs

Database Connection Optimization

  • Add HikariCP keepalive settings (180s interval)
  • Prevents Azure PostgreSQL from dropping idle connections
  • Applied to: analytics-service, data-processor, notification-service

Simplified Scaling

  • Remove EventHub scaling rules (redundant with cron rule + maxReplicas: 1)
  • Remove HTTP scaling rules (cron already ensures availability during working hours)
  • All services now use cron-only scaling: 6:55 AM - 5:00 PM Mon-Fri

New Warmup Endpoint

  • GET /api/analytics/warmup - lightweight DB query for connection warmup
  • Enhanced health checks with database status

- Change aggregation schedule from midnight to 7:00 AM (Europe/Berlin)
- Container scales up at 6:55 AM, ensuring scheduler can execute
- Remove unused EventHub and HTTP scaling rules from all services
- Simplify to cron-only scaling (6:55 AM - 5:00 PM Mon-Fri)

The midnight scheduler was failing because containers scale to 0 outside working hours. Moving to 7:00 AM ensures the container is active.
- Add keepalive-time (180s) to prevent Azure PostgreSQL dropping idle connections
- Configure minimum-idle (1) to maintain warm connections
- Set idle-timeout (5min), max-lifetime (10min), connection-timeout (30s)
- Apply to analytics-service, data-processor, and notification-service
- Add GET /api/analytics/warmup endpoint for connection pool warmup
- Enable database health indicator in actuator health endpoint
@sonarqubecloud
Copy link

@ad-altun ad-altun merged commit f80b7cf into main Jan 21, 2026
2 checks passed
@ad-altun ad-altun deleted the fix/scaling-and-db-connection-optimization branch January 21, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant