Skip to content

ADR 0002: Comprehensive Configuration Lifecycle Events

Author: AirCommerce Architecture Team • Scope: service-configuration

AirCommerce microservices rely on Spring Cloud Bus to synchronize distributed, in-memory configuration caches. Previously, the system utilized a rudimentary Event Notification pattern via a ConfigurationUpdatedEvent that transported the key of the modified configuration.

Upon auditing the legacy implementation, two critical enterprise architectural flaws were discovered:

  • Incomplete Lifecycle Tracking (Desynchronization): The configuration service only published events when an existing configuration was edited. If a configuration was created or deleted, no event was ever dispatched. This resulted in permanent cache desynchronization across the microservice ecosystem, as consumers were completely blind to these lifecycle changes.
  • Data Staleness Bug: Even when the ConfigurationUpdatedEvent was successfully received, the legacy util-configuration consumer incorrectly handled the fetch logic. If the namespace was already present in memory, it silently extracted the stale value from the local cache rather than fetching the updated state from the server. This effectively rendered the entire event-driven update mechanism broken.
  • Data Consistency: Ensure all microservices are perfectly synchronized across the entire configuration lifecycle (Create, Update, Delete).
  • Domain-Driven Design (DDD): Explicitly transport the state change intent alongside the domain key to allow consumers to react conditionally.
  • Performance: Utilize the domain key to enable pure zero round-trip HTTP cache evictions for deletions.
  • Granularity: Fix the data staleness bug by introducing targeted, granular fetches that update precisely the affected configuration.
  • Option 1: Fix Existing Event and Add Missing Events (e.g., ConfigurationCreatedEvent, ConfigurationDeletedEvent)
  • Option 2: Single Comprehensive Event with Database ID
  • Option 3 (Chosen): Single Comprehensive Event with Domain Key and Explicit Action

We chose Option 3 (Single Comprehensive Event with Domain Key and Explicit Action), because it unifies the lifecycle into a single predictable stream, explicitly communicates the state change, and leverages the domain key to allow consumers to perform pure zero round-trip cache evictions.

The diagram below shows how downstream services consume configurations via util-configuration and receive event-driven cache invalidations:

The legacy ConfigurationUpdatedEvent has been entirely replaced by a holistic ConfigurationChangedEvent documented in the Configuration Events Interface. This new event transports the domain key alongside a newly introduced ConfigurationChangeAction enum (CREATED, UPDATED, DELETED).

The Configuration Service now guarantees that this event is accurately dispatched during creations and deletions, closing the lifecycle blindspots.

Granular HTTP Fetching & Zero Round-Trip Deletions

Section titled “Granular HTTP Fetching & Zero Round-Trip Deletions”

The consumer-side cache management in util-configuration was completely overhauled to eliminate the data staleness bug:

  • For CREATED and UPDATED events, the consumer now correctly performs a targeted, granular GET /configurations/{key} HTTP call to fetch the fresh state and inject it into the cache.
  • For DELETED events, the consumer leverages the domain key to safely evict the entry from the local cache without executing any HTTP network calls.
ConfigurationChangedEvent event = new ConfigurationChangedEvent(
this,
busId,
String.format("%s:**", configuration.getNamespace()),
configuration.getKey(),
ConfigurationChangeAction.UPDATED
);
applicationEventPublisher.publishEvent(event);
@EventListener
public void handleConfigurationChangedEvent(ConfigurationChangedEvent event) {
if (event.getAction() == ConfigurationChangeAction.DELETED) {
// Zero-HTTP cache eviction
configurationNamespaceLoader.refreshNamespace();
log.info("Evicted deleted configuration key: {}", event.getKey());
} else if (event.getAction() != null) {
// Granular HTTP fetch for CREATED/UPDATED
ConfigurationResponse config = configurationClient.getConfigurationByKey(event.getKey());
updateLocalCache(config);
} else {
// Legacy fallback
configurationNamespaceLoader.refreshNamespace();
}
}

Option 1: Fix Existing Event and Add Missing Events

Section titled “Option 1: Fix Existing Event and Add Missing Events”
  • Good: Highly explicit event classes.
  • Bad: Clutters the event bus with multiple message types. Forces consumers to write multiple listener methods to handle basic CRUD cache invalidation.

Option 2: Single Comprehensive Event with Database ID

Section titled “Option 2: Single Comprehensive Event with Database ID”
  • Good: Unifies the event stream.
  • Bad: Forces consumers to make an HTTP round-trip even for DELETED events just to map the database ID to the domain key they actually use for caching, defeating the purpose of efficient evictions.

Option 3 (Chosen): Single Comprehensive Event with Domain Key and Explicit Action

Section titled “Option 3 (Chosen): Single Comprehensive Event with Domain Key and Explicit Action”
  • Good: Highly consolidated, guarantees cache consistency across all CRUD operations, fixes the data staleness bug via granular fetches, and enables pure zero round-trip network calls for cache evictions using the domain key.
  • Bad: Requires a single, targeted HTTP fetch by consumers for CREATED and UPDATED events.
  • Automated Lifecycle Integration Tests: Verified via end-to-end integration tests asserting that creating, updating, and deleting a configuration emits events with matching ConfigurationChangeAction values.
  • Local Cache Sync Tests: Consumer tests in util-configuration verify that a CREATED event triggers an HTTP fetch populating the local cache, an UPDATED event replaces the cache entry, and a DELETED event immediately evicts the key with zero outbound HTTP requests.
  • Legacy Fallback Compatibility: Assertions confirm that if a legacy event lacking an action payload arrives, util-configuration safely triggers a full namespace reload rather than failing.
  • Consumer Rollout: Downstream services must update to util-configuration version providing ConfigurationChangedEventListener to benefit from granular updates and zero-HTTP eviction.
  • Backward Compatibility: ConfigurationChangedEvent retains compatibility with older listeners expecting destination namespace patterns.