Dev.to WebDev 🛠 Dev 👁 0 📖 3 min read

Loyalty Membership Deals: How to Model Tiers, Perks and Cashback Without Breaking Your Checkout

Most "membership" features start as a boolean on the user table: is_member = true. Six months later the business team wants tiers, expiring perks, partner brand offers and instant cashback, and that boolean turns into a

Most "membership" features start as a boolean on the user table: is_member = true. Six months later the business team wants tiers, expiring perks, partner brand offers and instant cashback, and that boolean turns into a mess of if statements spread across the codebase.

This post walks through a simple, practical way to model loyalty membership deals so they stay flexible as the program grows. The examples come from how QR based cashback platforms work in India, where a customer scans a code on a genuine product and gets a reward credited to a wallet.

What a membership deal actually is

Strip away the marketing and a membership deal has four parts:

  1. Who qualifies (tier, region, number of past purchases)
  2. What triggers it (a purchase, a QR scan, a referral, a birthday)
  3. What the customer gets (cashback, bonus points, a gift card, a discount code)
  4. Limits (validity window, per user cap, total budget)

If your schema has a clean place for each of these, new campaigns become configuration instead of code.

A minimal data model

CREATE TABLE tiers (
  id SERIAL PRIMARY KEY,
  name TEXT NOT NULL,          -- Silver, Gold, Platinum
  min_lifetime_scans INT NOT NULL
);

CREATE TABLE deals (
  id SERIAL PRIMARY KEY,
  brand_id INT NOT NULL,
  min_tier_id INT REFERENCES tiers(id),
  trigger_type TEXT NOT NULL,  -- 'qr_scan', 'purchase', 'referral'
  reward_type TEXT NOT NULL,   -- 'cashback', 'points', 'gift_card'
  reward_value NUMERIC(10,2) NOT NULL,
  per_user_limit INT DEFAULT 1,
  budget_total NUMERIC(12,2),
  starts_at TIMESTAMPTZ,
  ends_at TIMESTAMPTZ
);

CREATE TABLE deal_redemptions (
  id BIGSERIAL PRIMARY KEY,
  deal_id INT REFERENCES deals(id),
  user_id BIGINT NOT NULL,
  source_ref TEXT UNIQUE,      -- QR code or order id, stops double claims
  created_at TIMESTAMPTZ DEFAULT now()
);

The UNIQUE constraint on source_ref matters more than anything else here. One physical QR code or one order should only ever pay out once, no matter how many times someone retries the request.

Tier evaluation should be boring

Do not recalculate tiers inside the checkout or scan flow. Run a small job that updates each user's tier when their lifetime scans or spend cross a threshold, and store the result. The deal engine then only has to compare two integers. This keeps the hot path fast and makes it easy to explain to a customer why they are Gold this month.

Keep rewards out of the payment path

A common mistake is mixing cashback logic into the payment gateway callback. If the reward service is down, payments should still succeed. Emit an event (purchase.completed or qr.scanned), let a separate reward worker pick it up, check eligibility, write the redemption row and credit the wallet. Withdrawals to a bank account through UPI can then run as their own queue with retries.

Make the deal visible to the customer

The best loyalty programs show members exactly what they unlocked and what is next. Store a short human readable description with each deal and return it in the API, so the app can show "You earned Rs 25 cashback, 2 more scans to reach Gold" right after a scan. That one line does more for repeat purchases than any email campaign.

A real world example

Platforms like Assured Rewards follow a similar pattern: partner brands print a unique QR code on each product, the customer scans it after buying, the code is verified as genuine and cashback lands in a wallet that can be withdrawn through UPI or used for gift cards. If you want to see how loyalty membership deals look from the customer side, it is a useful reference before you design your own.

Checklist before you ship

  • Every reward has an idempotency key (QR code, order id)
  • Tiers are precomputed, not calculated at request time
  • Deals have budgets and end dates, so a bug cannot drain the campaign
  • Reward processing is async and separate from payments
  • Customers can see what they earned and what is next

Get these five right and adding the next membership deal becomes a row in a table, not a sprint.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.