Checking access…

Skip to main content
Audience: CCG Platform Engineers

EIMP Split, Merge, and Delete Operations

Platform engineers implementing or debugging how wallet-customer-service mutates customer records in response to classified EIMP entity-change events (SPLIT, SPLIT_AND_MERGE, MERGE, DELETE).

Scope of this page: This page owns the CCG-side business logic β€” what happens to a Customer, EnterpriseCustomer, and MerchantCustomer record once an event has been classified. For the EIMP event contract itself (the entityChange/partyLinks payload schema, changeType values, sample payloads, and how eimpDeleted is derived upstream), see Kafka Entity Change Event Processing in Third Party Integrations.

Quick Reference

  • SPLIT / SPLIT_AND_MERGE: An enterprise identity is separated (and, for SPLIT_AND_MERGE, re-attached elsewhere)
  • MERGE: Enterprise identities are combined
  • DELETE: A single source record is dropped from an enterprise identity
  • eimpDeleted: A flag carried on every event; when true, the customer is inactivated regardless of event type
  • Benefits: Maintains data integrity, avoids orphaned associations, keeps identity mapping correct

How events reach this logic​

wallet-migration-service consumes the raw EIMP Kafka payload, classifies it into a reason (SPLIT, SPLIT_AND_MERGE, MERGE, DELETE) from the changeType values in records/oldRecords, derives the eimpDeleted flag, and forwards the classified event via Azure Event Grid. wallet-customer-service's EimpEntityChangeConsumer picks it up and dispatches to EimpEventProcessor:

Dispatch table
Event TypeHandler Method
SPLIThandleEimpSplitOrSplitAndMergeMasterIndividualEvent
SPLIT_AND_MERGEhandleEimpSplitOrSplitAndMergeMasterIndividualEvent
MERGEhandleEimpMergeMasterIndividualEvent
DELETEhandleEimpDeleteMasterIndividualEvent

Everything below is CCG business logic: None of what follows is part of the EIMP contract itself β€” it all runs inside these handlers once CCG has already classified the event. See Kafka Entity Change Event Processing for the contract side.

Architecture Diagram

Note: MERGE never purges payment methods in either path, and DELETE with eimpDeleted = false is a lighter path still β€” see the per-event-type tables below.

eimpDeleted changes the outcome for every event type

It is tempting to treat eimpDeleted as a SPLIT-only concern. It is not β€” it branches the behavior of every event type (SPLIT, SPLIT_AND_MERGE, MERGE, DELETE) and is the single most common source of "why didn't this customer get inactivated / why was this customer inactivated unexpectedly" incidents. Always check both the event type and the flag before reasoning about expected behavior.

Actions per event type and eimpDeleted​

SPLIT / SPLIT_AND_MERGE​

eimpDeleted = false β€” identity still exists
StepAction
1Look up EnterpriseCustomer by enterpriseId. If not found, log and complete (no-op).
2Create EimpMasterIndividualDetails tracking record with status PROCESSING.
3Purge all payment methods; verify deletion with up to 3 retry attempts.
4Delete merchant customer metadata only (merchant_customer_metadata rows). The MerchantCustomer identifier row is retained β€” see Why the MerchantCustomer relationship is never deleted.
5Refresh demographics from the Identity Service on both Customer and EnterpriseCustomer.
6Update HSID per the HSID handling rules.
7Mark tracking record COMPLETED.
eimpDeleted = true β€” identity split/split-and-merged AND deleted from EIMP
StepAction
1Inactivate Customer (inactive = true).
2Append an inactivation suffix to the enterprise ID on both Customer and EnterpriseCustomer.
3Clear EnterpriseCustomer.hsid unconditionally.
4Clear hsid on every retained MerchantCustomer row for the customer (best-effort; runs concurrently with steps 1–3).
5Create tracking record with status PROCESSING.
6Purge all payment methods.
7Delete merchant customer metadata only β€” the identifier row is still not deleted.
8No demographics refresh β€” Identity Service is not called.
9Mark tracking record COMPLETED.

MERGE​

eimpDeleted = false β€” identities merged, still exist
StepAction
1Look up EnterpriseCustomer by enterpriseId. If not found, log and complete (no-op).
2Create tracking record with status PROCESSING.
3Delete merchant customer metadata only (identifier row retained).
4Refresh demographics from the Identity Service on both Customer and EnterpriseCustomer.
5Update HSID per the HSID handling rules.
6Mark tracking record COMPLETED.

MERGE never deletes payment methods: This holds in both eimpDeleted states, including inactivation β€” unlike SPLIT/SPLIT_AND_MERGE/DELETE, which all purge payment methods when eimpDeleted = true.

eimpDeleted = true β€” merged AND the old identity was deleted from EIMP
StepAction
1Inactivate Customer; append inactivation suffix on both tables.
2Clear EnterpriseCustomer.hsid unconditionally; clear HSID on retained MerchantCustomer rows (best-effort, concurrent).
3Create tracking record with status PROCESSING.
4Delete merchant customer metadata only.
5No payment method deletion β€” MERGE never purges payment methods, including on inactivation.
6No demographics refresh.
7Mark tracking record COMPLETED.

DELETE​

eimpDeleted = false β€” a record was dropped, identity still exists
StepAction
1Conditionally clear HSID β€” see DELETE conditional HSID clearing.
2Validate that EnterpriseCustomer.customerId and Customer.customerId match for this enterpriseId. On mismatch, save FAILED and throw EimpEventProcessingException.
3Create tracking record with status PROCESSING.
4No payment method deletion, no merchant metadata deletion, no demographics refresh β€” this is the lightest of all six paths.
5Mark tracking record COMPLETED.

Lightest of all six paths: DELETE with eimpDeleted = false is the only path that touches neither payment methods, merchant metadata, nor demographics β€” it's effectively an HSID-only conditional check plus a consistency validation.

eimpDeleted = true β€” the enterprise identity was deleted entirely
StepAction
1Skip the conditional HSID clearing above β€” the unconditional clear in step 5 below supersedes it.
2Validate the Customer ID match, same as the false path β€” mismatch still fails the same way.
3Inactivate Customer; append inactivation suffix on both tables.
4Clear EnterpriseCustomer.hsid unconditionally; clear HSID on retained MerchantCustomer rows (best-effort, concurrent).
5Create tracking record with status PROCESSING.
6Purge all payment methods.
7Delete merchant customer metadata only β€” even a true DELETE never removes the MerchantCustomer identifier row.
8No demographics refresh.
9Mark tracking record COMPLETED.

Why the MerchantCustomer relationship is never deleted​

MerchantCustomerHandler.deleteAllMerchantCustomerMetadata is the only merchant-customer cleanup operation any EIMP reason ever calls β€” it removes stale merchant_customer_metadata rows but never deletes the MerchantCustomer identifier row itself, and never publishes MERCHANT_CUSTOMER_DELETED.

This is deliberate: Merchant Service correlates a PAYMENT_METHOD_DELETED event against the MerchantCustomer relationship. If an EIMP-triggered deletion tore that relationship down and Merchant Service processed MERCHANT_CUSTOMER_DELETED, a later payment-method-deletion event for the same customer (e.g. a MERGE followed by a SPLIT that purges payment methods) would reference a customer Merchant Service no longer recognizes, failing with a 500. This combination caused a production incident; no EIMP reason β€” including a true DELETE β€” deletes the relationship anymore.

Do not reintroduce MerchantCustomer row deletion from EIMP processing

This was a real production incident (CC-27560). Deleting the MerchantCustomer row from any EIMP handler β€” even for a true DELETE β€” can cause a later, in-flight PAYMENT_METHOD_DELETED event for the same customer to fail with a 500 at Merchant Service, because the relationship it needs to correlate against is already gone. If a future requirement genuinely needs this relationship torn down, it needs a new mechanism designed specifically for it, not a change to this cleanup path.

Retained rows and stale merchant-cached HSID​

Retaining the row indefinitely created a second-order risk: MerchantCustomer.hsid is a cache set independently by the merchant's own create/update flow, unrelated to EIMP. Before the fix above, a full inactivation deleted the row outright, so a stale HSID never outlived it; once rows are retained forever, a stale HSID on them could too β€” and CustomerQueryHandler#getCustomerByBaseHsid could resolve a merchant-supplied HSID to the wrong customer if a stale inactive row sorted ahead of a newly re-enrolled active one sharing the same HSID.

Two changes close this:

  1. MerchantCustomerHandler.clearHsidForInactivatedCustomer clears hsid to null on every retained MerchantCustomer row during inactivation, best-effort (a failure is logged, not propagated β€” inactivation still completes).
  2. CustomerQueryHandler#getCustomerByBaseHsid tries every candidate row, not just the first, short-circuiting on the first active match. This protects against stale rows that already exist, not just new ones.
Known, accepted behavior change β€” not a bug

GET /customers/{walletCustomerId}/details returns the MerchantCustomer.hsid field verbatim with no active-customer filtering, so for an inactivated customer its hsid changes from "last known merchant-cached value" to null going forward. This was flagged and consciously accepted during review (PR #4204) rather than fixed β€” no existing consumer was found to depend on the pre-fix value persisting after inactivation.

HSID handling​

Demographics refresh path (SPLIT, SPLIT_AND_MERGE, MERGE β€” eimpDeleted = false)
Identity Service responseResulting EnterpriseCustomer.hsid
Exactly 1 valid HSID (valid UUID)Set to that value
0 valid HSIDs, or identifiers/list are nullnull
2+ valid HSIDsnull β€” ambiguous, cleared as a safety measure
Exception during HSID processingLeft unchanged (logged)

DELETE conditional HSID clearing​

Applies only when eimpDeleted = false:

  1. Extract eimpOldRecords from the event's entityChange.
  2. Filter to records where sourceSystem = "HS_ID" and sourceRecordId is a valid UUID.
  3. If the current EnterpriseCustomer.hsid matches one of these old HS_IDs, clear it to null.
  4. Otherwise, leave it unchanged.

No-clearing conditions: A missing entityChange, empty/absent old records, a non-HS_ID source system, an invalid UUID, or a null current HSID all result in no clearing. A save failure here is logged and swallowed β€” processing continues.

Inactivation path (eimpDeleted = true β€” any event type)​

HSID is always unconditionally cleared on EnterpriseCustomer, and best-effort cleared on every retained MerchantCustomer row (see above).

Demographics update strategy​

EnterpriseCustomer and Customer follow different update rules

These two tables are updated from the same Identity Service response but with opposite null-handling β€” mixing them up is a common source of bugs when extending this logic.

  • EnterpriseCustomer always follows the Identity Service response verbatim β€” every field is overwritten, including to null when the Identity Service doesn't provide a value, to prevent stale data.
  • Customer uses additive updates β€” a field is only overwritten when the Identity Service provides a non-null, non-empty value.
  • Demographics are not refreshed when: eimpDeleted = true (any event type), on a DELETE event with eimpDeleted = false, when the enterprise ID isn't found in the Identity Service, or when the Identity Service returns no user.

Error handling​

Error handling table
ScenarioBehavior
EnterpriseCustomer not found by enterprise ID (SPLIT/MERGE)Log and complete gracefully (no-op)
Customer ID mismatch on DELETESave FAILED, throw EimpEventProcessingException
Customer or EnterpriseCustomer missing on DELETEThrow EimpEventProcessingException
Payment method deletion failsSet FAILED, save, complete gracefully
Merchant customer metadata cleanup failsError propagates β€” FAILED is saved, then rethrown
Merchant customer HSID clear fails (inactivation)Caught and logged; rest of processing still completes
Payment method verification exhausts retriesLog error, continue to merchant metadata cleanup
HSID clearing DB error (DELETE conditional path)Log warning, swallow, continue
Identity Service returns emptyLog error, skip demographics update, continue
Not every failure marks the tracking record FAILED

Several failures (HSID clearing, verification retries exhausted, merchant HSID clear on inactivation) are deliberately swallowed or logged-only so the rest of the flow still completes and the record still ends up COMPLETED. Don't assume a COMPLETED status means every substep succeeded β€” check the logs for partial failures too.

Summary matrix​

Event type Γ— eimpDeleted action matrix

Column abbreviations: S&M = SPLIT_AND_MERGE Β Β·Β  Ent. = EnterpriseCustomer Β Β·Β  Merch. = MerchantCustomer Β Β·Β  PMs = Payment Methods Β Β·Β  MC Row = the MerchantCustomer identifier row itself

EventDeleted?InactivateOverride EIDHSID (Ent.)HSID (Merch.)Purge PMsPurge MC RowPurge MetadataDemographics
SPLIT / S&Mfalse❌❌IdentityΒΉβŒβœ…βŒΒ²βœ…βœ…
SPLIT / S&Mtrueβœ…βœ…βœ…Β³βœ…βœ…βŒΒ²βœ…βŒ
MERGEfalse❌❌IdentityΒΉβŒβŒβŒΒ²βœ…βœ…
MERGEtrueβœ…βœ…βœ…Β³βœ…βŒβŒΒ²βœ…βŒ
DELETEfalse❌❌Cond.⁴❌❌❌❌❌
DELETEtrueβœ…βœ…βœ…Β³βœ…βœ…βŒΒ²βœ…βŒ

Footnotes

  1. Set per the Identity Service response rules β€” see HSID handling
  2. Retained, never deleted β€” see Why the MerchantCustomer relationship is never deleted
  3. Cleared unconditionally as part of inactivation
  4. Only if the current HSID matches an old HS_ID record in the event β€” see DELETE conditional HSID clearing

Key Components​

Class reference
  • EimpEntityChangeConsumer: Receives the classified event from the Azure Event Grid topic and dispatches by event type.
  • EimpEventProcessor: Central handler for SPLIT, SPLIT_AND_MERGE, MERGE, and DELETE; owns the eimpDeleted branching, inactivation, and status tracking logic described above.
  • DeleteAllCustomerPaymentMethodsCommandHandler: Bulk payment method deletion with retry-based verification.
  • MerchantCustomerHandler: Metadata-only cleanup (deleteAllMerchantCustomerMetadata) and inactivation-time HSID clearing (clearHsidForInactivatedCustomer) on retained MerchantCustomer rows.
  • IdentityService: Refreshes demographics and resolves HSID from the Identity Service.
  • EimpMasterIndividualDetails / EimpUpdateStatus: Tracks each event's processing status β€” valid values are PROCESSING, FAILED, COMPLETED (there is no separate ERROR status).

Best Practices​

  • Monitor the EimpMasterIndividualDetails table and logs for FAILED events and unusual patterns.
  • When touching this logic, test across all six event-type Γ— eimpDeleted combinations above β€” they diverge in payment method purging, demographics refresh, and HSID handling in non-obvious ways.
  • For the EIMP event payload shapes behind each scenario (new EID created, over-merge correction, memdrop deletion, etc.), see the sample payloads in Kafka Entity Change Event Processing.
Before changing MerchantCustomer deletion behavior

Re-read Why the MerchantCustomer relationship is never deleted and re-verify the Merchant Service correlation risk (CC-27560) before shipping any change here β€” this is the highest-blast-radius behavior on this page.