Membership Events
The memberships Lambda consumes the site-user-service-users Kinesis stream and translates membership lifecycle events from the user-service into subscription record updates in the billing-activity table. It moves no money — its sole responsibility is keeping subscription statuses consistent with membership state.
Event Filter
A Kinesis filter on the event source mapping (deploy/lambda.tf) passes twelve event types: UPGRADE, DOWNGRADE, CANCEL, RETRACT, AUTODOWNGRADED, GONETOCOLLECTIONS, PAYNOW, SUB_PAUSED, UNPAUSE, UNPAUSE_CHARGE, CLOSEACCOUNT, REACTIVATE.
Six of them have handlers (Handlers). The rest hit the dispatch switch’s default case and return ErrUnsupportedType: the record is reported as a batch-item failure and retried (UPGRADE/DOWNGRADE are served by the API endpoints — subscription_lifecycle.adoc#upgrade-downgrade; REACTIVATE by subscription_lifecycle.adoc#reactivation; AUTODOWNGRADED, GONETOCOLLECTIONS, and PAYNOW mutate nothing in this service).
Handlers
Every handler except CLOSEACCOUNT first fetches the user from the User Service and discards the event unless status == ACTIVE (a missing user is a logged no-op), then acquires the per-user billing lock (dynamo.adoc#locks) before reading and batch-writing records. CLOSEACCOUNT skips both the status check and the lock. All writes set last_run_date and land in billing-activity plus billing-activity-history.
| Event | Records matched | Effect |
|---|---|---|
|
|
|
|
|
Status → |
|
|
Clears |
|
All |
Soonest record → |
|
All |
Same as |
|
|
Status → |
Source: pkg/memberships/.
Error Handling
The Kinesis entry point reports partial batch failures by sequence number: successfully processed records are not retried, failed records are, and the event source mapping bisects a failing batch to isolate bad records. Unmarshal and decode failures are logged and reported the same way.