Skip to content

ADR 0010: Typed Table Configuration

Author: Emir Boyacı • Scope: util-configuration

AirCommerce microservices consume dynamic configurations managed by Configuration Service (service-configuration) and embedded via Configuration Util (util-configuration). Previously, the platform supported five configuration shapes: INPUT, SWITCH, DROPDOWN, MULTISELECT, and single-pair MAPPING.

When operations and engineering teams needed multi-column runtime matrices (such as fee tables, channel/cabin rule matrices, or multi-attribute feature overrides), storing raw JSON strings inside INPUT configurations introduced major defects:

  • No Server-Side Schema Enforcement: Arbitrary JSON strings bypassed column definitions, required-cell checks, boolean formatting, and allowed option sets, allowing malformed configurations to persist into MongoDB and propagate over RabbitMQ.
  • Repeated Client Parsing Boilerplate: Consuming microservices had to deserialize raw JSON strings manually and invent ad-hoc fallback handling for missing or malformed fields.
  • Ambiguous Scalar vs. List Payloads: Without a structured cell contract, JSON numbers or booleans sent by callers or UI forms could fail strict string deserialization, while accidental nested objects ({}) or arrays ([]) in scalar cells needed to fail fast.
  • Schema-Validated Matrix Persistence: Enforce column definitions, option constraints, required cells, and scalar-vs-list exclusivity server-side before committing MongoDB writes or emitting ConfigurationChangedEvents.
  • Polymorphic Wire Compatibility: Extend the existing sealed ConfigurationEntity, CreateConfigurationRequest, EditConfigurationRequest, and ConfigurationResponse hierarchies with ConfigurationType.TABLE without breaking the five existing configuration types.
  • Ergonomic Consumer SDK Contract: Support @ConfigurationValue private List<TableRow> injection with typed cell accessors, live reload on UPDATED, and baseline fallback on startup miss or DELETED.
  • Controlled Complexity: Keep column types flat (INPUT, SWITCH, DROPDOWN, MULTISELECT) and exclude nested MAPPING or TABLE columns.
  • Option 1: Store schema-less JSON strings in ConfigurationType.INPUT and parse per consumer service.
  • Option 2: Introduce an untyped List<Map<String, Object>> configuration type without column metadata or cell exclusivity.
  • Option 3 (Chosen): Introduce first-class ConfigurationType.TABLE across service-configuration and util-configuration with typed TableColumn/TableRow/TableCell contracts, Jackson 3 lenient scalar coercion, and server-side TableConfigurationValidator.

We chose Option 3: adding ConfigurationType.TABLE end-to-end across service-configuration and util-configuration as a first-class polymorphic subtype (type: "TABLE").

1. Column & Cell Schema (service-configuration and util-configuration)

Section titled “1. Column & Cell Schema (service-configuration and util-configuration)”
  • TableColumnType: Restricts columns to INPUT, SWITCH, DROPDOWN, and MULTISELECT (explicitly excluding nested MAPPING or TABLE types).
  • TableColumn: Declares key (^[a-zA-Z0-9\-_]*$), label, columnType, required, and selectableValues (required and non-empty for DROPDOWN and MULTISELECT).
  • TableCell Scalar/List Exclusivity: Each cell references columnKey and carries either scalar value (String) or list values (List<String>). MULTISELECT columns require values and forbid value; INPUT, SWITCH, and DROPDOWN columns require value and forbid values.
  • Jackson 3 Lenient Scalar Coercion: TableCell.LenientStringDeserializer (tools.jackson.databind.ValueDeserializer<String>) coerces VALUE_STRING, VALUE_NUMBER_INT, VALUE_NUMBER_FLOAT, VALUE_TRUE, and VALUE_FALSE via parser.getValueAsString() (passing VALUE_NULL as null), while explicitly rejecting non-scalar START_OBJECT ({}) and START_ARRAY ([]) tokens via context.handleUnexpectedToken(String.class, parser).

2. Server-Side Validation & Transactional Guarantees (service-configuration)

Section titled “2. Server-Side Validation & Transactional Guarantees (service-configuration)”

ConfigurationService invokes TableConfigurationValidator.validate(columns, rows) on both CreateTableConfigurationRequest and EditTableConfigurationRequest (including PUT /configurations/bulk):

  • Rejects empty/null column lists, blank/duplicate column keys, blank selectableValues entries, unknown or duplicate cell columnKeys within a row, non-boolean SWITCH strings (case-insensitive true/false), out-of-range DROPDOWN/MULTISELECT selections, and missing or blank/empty required cells.
  • On EditTableConfigurationRequest, omitting rows (null) clears existing rows on TableConfigurationEntity prior to ModelMapper mapping (MapperConfig) so stale rows are never retained.
  • CustomGlobalExceptionHandler maps InvalidTableConfigurationException to HTTP 400 Bad Request with ResponseCode.INVALID_REQUEST. Bulk validation failures abort the MongoDB transaction and publish zero lifecycle events.

3. Client SDK Contract (util-configuration)

Section titled “3. Client SDK Contract (util-configuration)”
@Component
public class FeeRuleService {
@ConfigurationValue("pricing.ancillary-fee-matrix")
private List<TableRow> feeRules = List.of();
public BigDecimal feeForChannel(String channel) {
return feeRules.stream()
.filter(row -> row.getString("channel").filter(channel::equals).isPresent())
.filter(row -> row.getBoolean("active", false))
.findFirst()
.map(row -> row.getBigDecimal("feeAmount", BigDecimal.ZERO))
.orElse(BigDecimal.ZERO);
}
}
  • ConfigurationTypeUtils.determineConfigurationType(Field) inspects generic List<TableRow> fields and resolves ConfigurationType.TABLE.
  • ConfigurationValueExtractor.extractValue(...) extracts TableConfigurationResponse#getRows() and throws ConfigurationExtractionException if the remote type mismatches TABLE.
  • TableRow exposes defensive typed accessors: getString(columnKey) (Optional<String>), getBoolean(columnKey, defaultValue), getBigDecimal(columnKey, defaultValue), and getList(columnKey) (List<String>), returning safe defaults when cells are missing or unparseable.
  • ConfigurationValueInjector, ConfigurationChangedEventListener, and ConfigurationActuatorEndpoint preserve default fallback on missing keys/DELETED events, live reload on UPDATED events, and expose remoteType = "TABLE".
  • Good: Zero schema changes to service-configuration or util-configuration.
  • Bad: No validation on write, silent consumer runtime failures, and duplicated parsing logic across services.

Option 2: Untyped List<Map<String, Object>>

Section titled “Option 2: Untyped List<Map<String, Object>>”
  • Good: Flexible ad-hoc row shapes without defining columns.
  • Bad: Cannot enforce DROPDOWN/MULTISELECT option sets, SWITCH booleans, required columns, or reject nested {}/[] payloads consistently.

Option 3 (Chosen): First-Class ConfigurationType.TABLE

Section titled “Option 3 (Chosen): First-Class ConfigurationType.TABLE”
  • Good: Strong server-side validation, clean polymorphic REST contract, lenient scalar JSON coercion with strict non-scalar rejection, and zero-boilerplate List<TableRow> injection.
  • Bad: Requires synchronized TableCell/TableColumn/TableRow model definitions across service-configuration and util-configuration and a dedicated UI editor in app-core-management.
  • Server-Side Verification (service-configuration): mvn verify validates TableCellTest (Jackson 3 scalar coercion and {}/[] rejection), TableConfigurationValidatorTest (positive/negative schema, cell exclusivity, required fields), CustomGlobalExceptionHandlerTest (HTTP 400 / ResponseCode.INVALID_REQUEST), ConfigurationServiceTest (including clearing rows on null edit), and integration tests for CRUD and bulk transaction rollback with zero emitted events.
  • Client SDK Verification (util-configuration): mvn verify validates TableCellTest, TableConfigurationResponseTest (wire round-trip), TableRowTest (typed accessors and fallbacks), ConfigurationTypeUtilsTest, ConfigurationValueExtractorTest, ConfigurationValueInjectorTest, ConfigurationChangedEventListenerTest (UPDATED reload / DELETED revert), and ConfigurationActuatorEndpointTest (remoteType = "TABLE").
  • Documentation Audit (architecture-portal): npm run audit validates ontology integrity, ADR frontmatter schema, internal links, formatting, and full Astro static build.
  • Backward Compatibility: Existing INPUT, SWITCH, DROPDOWN, MULTISELECT, and MAPPING configurations, MongoDB indexes, RBAC roles, and REST paths remain unchanged.
  • Consumer Adoption: Microservices upgrade util-configuration via the centralized BOM (ADR 0005) and opt into List<TableRow> per key without forced migrations.
  • Configuration UI Follow-Up: Interactive table editing in app-core-management (configuration-ui) is tracked separately and remains out of scope for this backend and SDK rollout.