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; whentrue, 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 Type | Handler Method |
|---|---|
SPLIT | handleEimpSplitOrSplitAndMergeMasterIndividualEvent |
SPLIT_AND_MERGE | handleEimpSplitOrSplitAndMergeMasterIndividualEvent |
MERGE | handleEimpMergeMasterIndividualEvent |
DELETE | handleEimpDeleteMasterIndividualEvent |
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 typeIt 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
| Step | Action |
|---|---|
| 1 | Look up EnterpriseCustomer by enterpriseId. If not found, log and complete (no-op). |
| 2 | Create EimpMasterIndividualDetails tracking record with status PROCESSING. |
| 3 | Purge all payment methods; verify deletion with up to 3 retry attempts. |
| 4 | Delete merchant customer metadata only (merchant_customer_metadata rows). The MerchantCustomer identifier row is retained β see Why the MerchantCustomer relationship is never deleted. |
| 5 | Refresh demographics from the Identity Service on both Customer and EnterpriseCustomer. |
| 6 | Update HSID per the HSID handling rules. |
| 7 | Mark tracking record COMPLETED. |
eimpDeleted = true β identity split/split-and-merged AND deleted from EIMP
| Step | Action |
|---|---|
| 1 | Inactivate Customer (inactive = true). |
| 2 | Append an inactivation suffix to the enterprise ID on both Customer and EnterpriseCustomer. |
| 3 | Clear EnterpriseCustomer.hsid unconditionally. |
| 4 | Clear hsid on every retained MerchantCustomer row for the customer (best-effort; runs concurrently with steps 1β3). |
| 5 | Create tracking record with status PROCESSING. |
| 6 | Purge all payment methods. |
| 7 | Delete merchant customer metadata only β the identifier row is still not deleted. |
| 8 | No demographics refresh β Identity Service is not called. |
| 9 | Mark tracking record COMPLETED. |
MERGEβ
eimpDeleted = false β identities merged, still exist
| Step | Action |
|---|---|
| 1 | Look up EnterpriseCustomer by enterpriseId. If not found, log and complete (no-op). |
| 2 | Create tracking record with status PROCESSING. |
| 3 | Delete merchant customer metadata only (identifier row retained). |
| 4 | Refresh demographics from the Identity Service on both Customer and EnterpriseCustomer. |
| 5 | Update HSID per the HSID handling rules. |
| 6 | Mark 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
| Step | Action |
|---|---|
| 1 | Inactivate Customer; append inactivation suffix on both tables. |
| 2 | Clear EnterpriseCustomer.hsid unconditionally; clear HSID on retained MerchantCustomer rows (best-effort, concurrent). |
| 3 | Create tracking record with status PROCESSING. |
| 4 | Delete merchant customer metadata only. |
| 5 | No payment method deletion β MERGE never purges payment methods, including on inactivation. |
| 6 | No demographics refresh. |
| 7 | Mark tracking record COMPLETED. |
DELETEβ
eimpDeleted = false β a record was dropped, identity still exists
| Step | Action |
|---|---|
| 1 | Conditionally clear HSID β see DELETE conditional HSID clearing. |
| 2 | Validate that EnterpriseCustomer.customerId and Customer.customerId match for this enterpriseId. On mismatch, save FAILED and throw EimpEventProcessingException. |
| 3 | Create tracking record with status PROCESSING. |
| 4 | No payment method deletion, no merchant metadata deletion, no demographics refresh β this is the lightest of all six paths. |
| 5 | Mark 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
| Step | Action |
|---|---|
| 1 | Skip the conditional HSID clearing above β the unconditional clear in step 5 below supersedes it. |
| 2 | Validate the Customer ID match, same as the false path β mismatch still fails the same way. |
| 3 | Inactivate Customer; append inactivation suffix on both tables. |
| 4 | Clear EnterpriseCustomer.hsid unconditionally; clear HSID on retained MerchantCustomer rows (best-effort, concurrent). |
| 5 | Create tracking record with status PROCESSING. |
| 6 | Purge all payment methods. |
| 7 | Delete merchant customer metadata only β even a true DELETE never removes the MerchantCustomer identifier row. |
| 8 | No demographics refresh. |
| 9 | Mark 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.
MerchantCustomer row deletion from EIMP processingThis 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:
MerchantCustomerHandler.clearHsidForInactivatedCustomerclearshsidtonullon every retainedMerchantCustomerrow during inactivation, best-effort (a failure is logged, not propagated β inactivation still completes).CustomerQueryHandler#getCustomerByBaseHsidtries 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.
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 response | Resulting EnterpriseCustomer.hsid |
|---|---|
| Exactly 1 valid HSID (valid UUID) | Set to that value |
0 valid HSIDs, or identifiers/list are null | null |
| 2+ valid HSIDs | null β ambiguous, cleared as a safety measure |
| Exception during HSID processing | Left unchanged (logged) |
DELETE conditional HSID clearingβ
Applies only when eimpDeleted = false:
- Extract
eimpOldRecordsfrom the event'sentityChange. - Filter to records where
sourceSystem = "HS_ID"andsourceRecordIdis a valid UUID. - If the current
EnterpriseCustomer.hsidmatches one of these old HS_IDs, clear it tonull. - 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 rulesThese 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.
EnterpriseCustomeralways follows the Identity Service response verbatim β every field is overwritten, including tonullwhen the Identity Service doesn't provide a value, to prevent stale data.Customeruses 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 witheimpDeleted = 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
| Scenario | Behavior |
|---|---|
EnterpriseCustomer not found by enterprise ID (SPLIT/MERGE) | Log and complete gracefully (no-op) |
| Customer ID mismatch on DELETE | Save FAILED, throw EimpEventProcessingException |
| Customer or EnterpriseCustomer missing on DELETE | Throw EimpEventProcessingException |
| Payment method deletion fails | Set FAILED, save, complete gracefully |
| Merchant customer metadata cleanup fails | Error propagates β FAILED is saved, then rethrown |
| Merchant customer HSID clear fails (inactivation) | Caught and logged; rest of processing still completes |
| Payment method verification exhausts retries | Log error, continue to merchant metadata cleanup |
| HSID clearing DB error (DELETE conditional path) | Log warning, swallow, continue |
| Identity Service returns empty | Log error, skip demographics update, continue |
FAILEDSeveral 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
| Event | Deleted? | Inactivate | Override EID | HSID (Ent.) | HSID (Merch.) | Purge PMs | Purge MC Row | Purge Metadata | Demographics |
|---|---|---|---|---|---|---|---|---|---|
| SPLIT / S&M | false | β | β | IdentityΒΉ | β | β | βΒ² | β | β |
| SPLIT / S&M | true | β | β | β Β³ | β | β | βΒ² | β | β |
| MERGE | false | β | β | IdentityΒΉ | β | β | βΒ² | β | β |
| MERGE | true | β | β | β Β³ | β | β | βΒ² | β | β |
| DELETE | false | β | β | Cond.β΄ | β | β | β | β | β |
| DELETE | true | β | β | β Β³ | β | β | βΒ² | β | β |
Footnotes
- Set per the Identity Service response rules β see HSID handling
- Retained, never deleted β see Why the MerchantCustomer relationship is never deleted
- Cleared unconditionally as part of inactivation
- Only if the current HSID matches an old
HS_IDrecord 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 forSPLIT,SPLIT_AND_MERGE,MERGE, andDELETE; owns theeimpDeletedbranching, 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 retainedMerchantCustomerrows.IdentityService: Refreshes demographics and resolves HSID from the Identity Service.EimpMasterIndividualDetails/EimpUpdateStatus: Tracks each event's processing status β valid values arePROCESSING,FAILED,COMPLETED(there is no separateERRORstatus).
Best Practicesβ
- Monitor the
EimpMasterIndividualDetailstable and logs forFAILEDevents and unusual patterns. - When touching this logic, test across all six event-type Γ
eimpDeletedcombinations 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.
MerchantCustomer deletion behaviorRe-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.