Skip to content

refactor(consumer): remove lazy mode, keep only eager start #349

@gandalf-at-lerian

Description

@gandalf-at-lerian

Context

The MultiTenantConsumer currently supports two consumer start modes via the EagerStart config flag:

  • Eager (default, EagerStart=true): consumers are started immediately for all discovered tenants at startup and during sync.
  • Lazy (EagerStart=false): consumers are only started on-demand via EnsureConsumerStarted().

Problem

Lazy mode has zero callers across the entire codebase. No app (Midaz, Tenant Manager, or any other service) calls EnsureConsumerStarted() externally. The only trigger that would start consumers in lazy mode is the sync loop itself — which is exactly what eager already does.

This means:

  • The EagerStart flag and its conditional branches add complexity with no practical benefit today.
  • The public EnsureConsumerStarted() API is exported but unused.
  • Two code paths need to be maintained and tested for a single effective behavior.

Proposed Changes

  1. Remove the EagerStart config field from MultiTenantConfig (or deprecate/ignore it).
  2. Make eager the only behavior: Run() always starts consumers for discovered tenants; syncTenants() always starts consumers for newly discovered tenants.
  3. Remove the public EnsureConsumerStarted() API — no external callers exist.
  4. Keep ensureConsumerStarted() as internal method — the double-check locking is still needed since sync can run concurrently.
  5. Remove lazy-specific test cases and simplify existing tests that parameterize on EagerStart.

Impact

  • Simplifies the consumer startup flow to a single code path.
  • Reduces config surface area.
  • No behavioral change for any existing deployment (all use eager today).

Files Affected

  • commons/tenant-manager/consumer/multi_tenant.go — remove EagerStart field, simplify Run()
  • commons/tenant-manager/consumer/multi_tenant_consume.go — remove public EnsureConsumerStarted()
  • commons/tenant-manager/consumer/multi_tenant_sync.go — remove conditional branches in eagerStartKnownTenants() and syncTenants()
  • commons/tenant-manager/consumer/multi_tenant_stats.go — remove connectionMode() helper
  • Test files — simplify parameterized tests

Note

If lazy mode becomes needed in the future (e.g., hundreds of tenants with sporadic activity), it can be re-added as a feature at that point. No need to carry the complexity now.

Requested by: @jeffersonRodrigues (CTO)

Metadata

Metadata

Assignees

No one assigned

    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