Is running ClickHouse migrations on every web container startup safe when scaling? (golang-migrate concurrency) #10697
Describe your questionI noticed that the Langfuse web container runs ClickHouse migrations at startup via: entrypoint.sh → clickhouse/scripts/up.sh → migrate up. If multiple web pods start simultaneously (e.g., a Deployment with >1 replica), all of them execute migrate up in parallel. My questions:
Langfuse Cloud or Self-Hosted?Self-Hosted If Self-HostedNo response If Langfuse CloudNo response SDK and integration versionsNo response Pre-Submission Checklist
|
Replies: 1 comment 5 replies
|
Based on the available sources, running ClickHouse migrations concurrently from multiple web containers can cause issues. Here's what the documentation reveals: Migration Concurrency IssuesWhen migration errors occur, the migration tool marks your database as 'dirty' to prevent additional migrations from running on an inconsistent database state(1). The sources indicate that race conditions between container startup and ClickHouse availability cause migration failures(2). ECS task restarts can interrupt migrations mid-process, leaving them in a dirty state(2). Connection issues between the web container and ClickHouse during startup create race conditions(2). What Happens During Concurrent MigrationsIf you encounter a migration error, you'll see an error message like "Dirty database version 1. Fix and force version" even after fixing the erred migration(1). This means your database has been marked as 'dirty'(1). Recommended Best PracticesThe documentation provides several prevention strategies(2):
Recovery from Failed MigrationsIf migrations fail and mark the database as dirty, you need to investigate whether the migration was partially applied or not applied at all(1). After determining the actual state, force your database to the version that accurately reflects its current state(1). The safest approach for production environments with multiple replicas is to disable automatic migrations and run them manually during controlled maintenance windows to avoid concurrent execution issues. 📚 Sources:
Have another question? Just tag @inkeep. |
@furqan-shaikh-dev Usually, we see that one pod starts and marks the migration as
dirtyand other containers starting around the same time will fail for this reason. When the initial pod succeeds, all other new pods will then succeed in their startup with nothing to do. Therefore, I don't expect this issue to occur often. The main recommendations here are 2. (Startup Probe timeouts) and 3. (Ensure ClickHouse is ready before Langfuse is being deployed).If you want to avoid migration issues fully, disabling the ClickHouse migrations should work well. You'll have to watch whether there were any migrations on very upgrade though.
The Postgres migrations are safer in their nature due to the l…