← Back to the deskJeevan’s field notes / Engineering casebook
Engineering casebookNo. 01.5
← All case studies

Subscriptions · Product infrastructure

Keeping access in step with a subscription.

Coordinating payment events, plan changes and usage limits so product access follows a clear set of rules.

My contribution
Backend & subscription engineering
Context
Professional work · 2026
TypeScriptNode.jsPostgreSQLDrizzleRazorpay
My responsibility
Built subscription and entitlement workflows for a learning platform.
The key decision
Separate gateway events from access policy, with transactional payment updates and explicit grace-period rules.
What changed
Plan changes, usage quotas and refund eligibility resolved through shared backend rules.

The problem & my responsibilities

A subscription is more than a successful checkout. Payment confirmations can arrive more than once, upgrades can await mandate confirmation, and usage continues while a plan changes. The learning product needs a consistent answer to whether an account can start or continue a session.

I developed the subscription and entitlement workflows around those transitions: usage quotas, plan upgrades and downgrades, pause and resume, grace-period access and refund eligibility. Payment integration and product access meet at explicit backend state changes.

Constraints that shaped the work

  • Repeated gateway events for the same payment
  • Account-level limits across multiple learners
  • Pending upgrades while usage continues
  • Refund decisions that depend on transaction history

How the system fits together

Architecture / system overview
  1. 01
    ConfirmVerify the gateway signature and find the recorded transaction
  2. 02
    ApplyClaim the pending payment and update subscription state in a transaction
  3. 03
    ResolveSelect the effective plan, grace window and usage allowance
  4. 04
    EnforceCheck session access and record account usage

The consequential decisions

Choices, alternatives and the costs that come with each decision.
DecisionChoiceAlternativeTrade-off
Payment processingA conditional transaction-state updateApply every incoming payment notificationOnly the handler that claims a pending transaction applies its entitlement changes. Repeated notifications can be acknowledged without granting the same purchase again.
Access policyResolve an effective plan on the backendLet each client interpret payment statusThe subscription engine combines plan state, usage and grace expiry in one place. Clients consume the resulting allowance instead of recreating billing policy.
Upgrade graceA pending plan with an explicit expiryOverwrite the current plan before confirmationTemporary access can follow the pending plan while preserving the existing subscription and usage history. Expiry remains part of every quota calculation.
Refund eligibilityDeterministic rules over transaction historyAd hoc checks in individual endpointsA separate rule engine returns eligibility, reason codes and time windows that can be tested independently of the payment gateway.

Where the work got difficult

Handle the same payment twice

Related gateway notifications can refer to one charge. The processing path checks recorded status, then conditionally claims the pending transaction inside the database transaction before applying changes.

Change plans without losing usage

An upgrade affects what an account may use next; it should not erase what it has already consumed. Effective-plan selection and daily usage remain separate inputs to the access decision.

Operating considerations

Verification & reconciliation

Verify incoming payment signatures before processing. A payment that cannot be matched to an internal transaction needs investigation rather than an inferred entitlement.

Time boundaries

Daily usage follows the product’s IST day, while grace and refund windows use explicit timestamps. Checks at expiry are as important as the ordinary active-subscription path.

Recovery

Payment failure, pause, resume and refund are distinct state transitions. Their effects on access need to remain understandable to both the learner and the support team.

Outcomes & lessons

The implementation provides shared backend rules for account access, quotas, plan changes and refund eligibility. Transactional payment handling and explicit grace expiry make the relationship between a purchase and its product access inspectable.

A subscription system earns trust when its access rules remain understandable through failure, delay and change.

Jeevan Jyoti SrivastavaThink → build → understand