Skip to content

Ensure concurrency safety when running multiple instances #3

@GianlucaFicarelli

Description

@GianlucaFicarelli

At the moment we deploy only one instance of the service, but in the future we may want to allow to start multiple instances to scale horizontally.

Before doing that we should ensure that the service works correctly even in that case.

In particular:

  1. alembic migration: it's executed when the container is started, before starting uvicorn. If multiple containers are started at the same time there can be a race condition that could cause the migration to fail. Possible solutions:
    1. Ensure that the container running the migration acquires a lock. The other containers will wait, then skip the migration because the db is already updated.
    2. Run the migration as a step of the CI executing the deployment
    3. Use other mechanisms for leader election
    4. Run the migration manually (I would avoid that if possible)
  2. tasks: the container runs some tasks:
    1. queue_consumers (they consume messages from the oneshot, longrun, storage queues)
    2. job_chargers (they run periodically and charge the user for the running or finished uncharged oneshot, longrun, storage jobs)

(migrated from BlueBrain/accounting-service#54)

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions