How to Design a Promotion Eligibility Engine Without Hard-Coding Every Deal
Promotions look simple from the outside. Spend $50 and get $10 off. Buy two and get one free. Save 20 percent on selected products. Free shipping for members. Use a coupon before Friday. For shoppers, these are sho
Promotions look simple from the outside.
Spend $50 and get $10 off.
Buy two and get one free.
Save 20 percent on selected products.
Free shipping for members.
Use a coupon before Friday.
For shoppers, these are short marketing messages.
For developers, each promotion represents a collection of rules that must be evaluated correctly.
The problem becomes difficult when an e-commerce platform has hundreds of promotions running at the same time.
If every new deal requires another collection of hard-coded if statements, the pricing system eventually becomes difficult to understand, test, and maintain.
A better approach is to treat promotion eligibility as its own domain.
Start by Separating Eligibility From Reward
Most promotions contain two different questions.
First:
Does this order qualify?
Second:
What benefit should be applied?
Those should not necessarily be handled by the same logic.
Consider:
Spend $100 on eligible electronics and receive $20 off.
Eligibility includes:
customer has enough eligible merchandise
products belong to the electronics category
excluded brands are removed
promotion is currently active
customer is in an allowed region
Reward is simply:
$20 off
Separating those concepts makes the system much easier to extend.
Represent Rules as Data
Instead of writing code such as:
if subtotal >= 100 and category == "electronics":
discount = 20
represent the promotion as structured data.
Conceptually:
Promotion type:
Fixed order discount
Minimum eligible spend:
100
Required category:
Electronics
Excluded brands:
Brand X
Reward:
20
Start date:
November 20
End date:
November 30
Now the promotion engine can interpret the rule without requiring a new deployment for every campaign.
Create Reusable Condition Types
Most promotions are built from a relatively small collection of conditions.
Examples include:
Minimum order value
Maximum order value
Required product
Required category
Excluded product
Excluded category
Minimum quantity
Customer segment
Membership status
Geographic region
Payment method
Date range
First purchase
Coupon code
Instead of implementing complete promotions individually, implement reusable condition evaluators.
A campaign then becomes a combination of those building blocks.
Use Explicit Boolean Logic
Some promotions require all conditions.
For example:
Customer must be a member
AND
Order must exceed $75
AND
Purchase must occur before midnight
Others may allow alternatives:
Customer is a premium member
OR
Customer has a promotional coupon
Your rule representation should support explicit logical groups.
For example:
ALL:
Membership = Premium
Subtotal >= 75
Date <= 2026-11-30
This is much safer than relying on hidden evaluation order inside application code.
Define the Eligible Basket
A common source of promotion bugs is treating the entire order subtotal as eligible.
Imagine a cart contains:
Laptop: $900
Gift card: $100
Promotion:
Spend $950 and receive $100 off electronics.
The raw cart subtotal is:
$1,000
But if gift cards are excluded, eligible spend is only:
$900
The order should not qualify.
Your promotion engine therefore needs to calculate:
order subtotal
and
promotion-eligible subtotal
separately.
Eligibility Should Work at Multiple Levels
Promotion rules may apply to:
customer
order
line item
product
category
seller
payment
shipping method
A useful rule engine understands those scopes.
For example:
Customer rule:
New customer only
Product rule:
Selected headphones
Quantity rule:
At least 2
Payment rule:
Specific card type
Reward:
15 percent off
All four dimensions contribute to one promotion decision.
Make Exclusions First-Class Rules
Marketing teams frequently describe what a promotion includes.
Engineering systems also need to represent what it excludes.
Examples:
All accessories except Apple products
All software except subscriptions
Sitewide discount excluding gift cards
Free shipping except oversized items
Do not hide exclusions inside product-specific code.
Represent them explicitly.
This makes promotions easier to explain and debug.
Determine Rule Evaluation Order
Some checks are cheap.
Others are expensive.
For example:
Checking whether the promotion is active is trivial.
Loading detailed customer purchase history may require database queries.
A sensible evaluator can test inexpensive rejection conditions first.
Conceptually:
Promotion active?
No → reject immediately.
Correct region?
No → reject.
Correct customer type?
No → reject.
Required purchase history?
Now perform expensive lookup.
Short-circuit evaluation can significantly reduce unnecessary processing.
Return Reasons, Not Just True or False
A weak eligibility API returns:
eligible = false
A more useful response returns:
eligible = false
reason = MINIMUM_SPEND_NOT_MET
required = 100
current = 83
This is valuable for:
user interfaces
customer support
analytics
debugging
testing
The frontend can now display:
Add $17 more to qualify for this offer.
Explainability should be built into the promotion engine.
Support Near-Eligibility
The engine can also distinguish between:
not eligible
and
almost eligible.
Suppose:
Promotion threshold: $100
Current eligible subtotal: $94
The system can calculate:
$6 remaining
That enables useful UI such as:
Spend $6 more to unlock free shipping.
This is much easier when the promotion engine exposes structured eligibility information.
Prevent Invalid Rule Combinations
If promotions are configured through an admin interface, users may create contradictory rules.
For example:
Required category:
Shoes
Excluded category:
Shoes
Or:
Minimum subtotal:
$100
Maximum subtotal:
$50
Validate promotion configuration before activation.
A rule engine should reject impossible campaigns instead of waiting for customers to discover them.
Version Promotion Definitions
Promotion rules can change during a campaign.
Suppose a promotion initially says:
Spend $100, save $15.
Two days later it becomes:
Spend $80, save $15.
Historical orders should still be associated with the rule version that applied when they were placed.
Record:
promotion_id
promotion_version
evaluation timestamp
This makes customer-service investigations much easier.
Treat Time Carefully
Time-based eligibility is more complicated than:
current_time < end_time.
You may need to consider:
timezone
store region
campaign timezone
daylight saving changes
order creation time
payment completion time
For example:
Promotion ends:
November 30 at 11:59 PM Eastern Time
A customer in California may see a different local clock.
Define which timezone controls eligibility.
Coupons Are Usually Inputs to Rules
A coupon code should not directly mean:
apply discount.
Instead:
Customer enters code.
System finds promotion.
Promotion engine evaluates eligibility.
If eligible:
apply reward.
This prevents a valid coupon from bypassing:
minimum spend
customer restrictions
product exclusions
usage limits
date restrictions
Track Usage Limits Separately
Some promotions have constraints such as:
one use per customer
first 10,000 orders
maximum 3 uses per account
These rules require state.
The eligibility engine may need access to:
customer promotion history
global redemption counters
order history
Be careful with concurrency when limits are strict.
Concurrency Can Create Oversubscription
Imagine:
Only 100 redemptions allowed.
Current count:
Two customers check out simultaneously.
Both read:
Both appear eligible.
Both redeem.
Final count:
The system needs atomic reservation or another concurrency-control mechanism.
Promotion eligibility and promotion redemption are related but different operations.
Use Reservation for Limited Promotions
A safer workflow might be:
Evaluate promotion.
Reserve redemption slot.
Complete checkout.
Finalize redemption.
If checkout fails:
Release reservation.
This pattern is useful for:
limited coupons
flash-sale allocations
exclusive inventory offers
limited cashback campaigns
Separate Eligibility From Redemption
Eligibility answers:
Could this customer use the promotion?
Redemption answers:
Did this transaction actually consume the promotion?
Do not increment usage counters simply because a user viewed the cart.
Consumption should normally occur only when the appropriate transaction stage completes.
Handle Promotion Stacking Explicitly
Eventually someone will ask:
Can these two promotions be used together?
Possible policies include:
No promotions can stack.
Only one order-level promotion.
Shipping promotions can stack with product discounts.
Loyalty discounts can stack with coupons.
Best discount wins.
Your promotion engine needs explicit compatibility rules.
Create Promotion Groups
One approach is assigning promotions to exclusivity groups.
For example:
ORDER_DISCOUNT
PRODUCT_DISCOUNT
SHIPPING
LOYALTY
Then define:
Only one ORDER_DISCOUNT can apply.
One SHIPPING promotion may also apply.
LOYALTY can stack with both.
This is much clearer than comparing every possible pair of campaigns manually.
Determine Which Promotion Wins
Suppose two exclusive discounts apply:
Promotion A:
$15 off
Promotion B:
20 percent off
Which one should the system choose?
Possible strategies:
Highest customer savings
Highest merchant priority
First qualified promotion
Explicit ranking
The rule should be deterministic.
Calculate Before Displaying Savings
Marketing interfaces often want to show:
You saved $35.
That number should come from the pricing engine rather than being calculated independently by the frontend.
If multiple services calculate savings differently, customers will eventually see conflicting totals.
Keep Evaluation Deterministic
Given the same:
cart
customer
promotion definitions
time
the engine should ideally produce the same result.
Avoid hidden inputs.
Determinism makes:
testing
debugging
replay
customer support
much easier.
Log Promotion Decisions
When an order receives or rejects a promotion, useful logs might include:
promotion ID
promotion version
customer ID
eligible subtotal
conditions evaluated
conditions failed
reward calculated
stacking decision
timestamp
You may not need to store every detail forever.
But enough context should exist to explain important pricing decisions.
Build an Evaluation Trace
For complicated promotions, create a trace.
For example:
Promotion:
HOLIDAY20
Active date:
PASS
Region:
PASS
Customer segment:
PASS
Eligible subtotal >= $100:
FAIL
Current eligible subtotal:
$86
Final result:
NOT ELIGIBLE
This is extremely useful for internal support tools.
Use the Same Engine Everywhere
Do not create separate promotion logic for:
product page
cart
checkout
mobile application
customer support
API
If each surface implements rules independently, inconsistencies are inevitable.
Create one authoritative promotion service or domain layer.
Every interface should ask the same engine.
Frontend Logic Should Be Informational
The frontend can predict or display eligibility.
But final pricing should be confirmed by the backend.
Users can manipulate client-side state.
A coupon that appears eligible in JavaScript should still be validated on the server before the transaction is accepted.
Cache Carefully
Promotion rules may be read frequently.
Caching can improve performance.
But campaigns also change.
If marketing disables a promotion, how quickly should every application instance notice?
Define:
cache lifetime
invalidation strategy
version checks
Never allow a long-lived stale cache to continue honoring an expired or disabled promotion unexpectedly.
Test Rules as Combinations
Testing only one rule at a time is not enough.
Create cases combining:
threshold + category
category + exclusion
customer segment + coupon
coupon + date
membership + region
stacking + threshold
usage limit + concurrency
Most bugs appear where rules interact.
Use Boundary Tests
Promotion rules contain many numerical boundaries.
For:
Spend $100, save $20
test:
$99.99
$100.00
$100.01
For:
Maximum 3 redemptions
test:
0
2
3
4
Boundary tests catch many pricing errors cheaply.
Use Property-Based Testing
Some invariants should always hold.
For example:
Discount cannot make eligible merchandise total negative.
Allocated discount cannot exceed the promotion reward.
An expired promotion cannot be redeemed.
A promotion outside the customer's region cannot apply.
Property-based tests can generate many carts and check those rules automatically.
Build a Promotion Simulator
Before launching a campaign, allow internal users to simulate orders.
Input:
customer
products
quantities
region
date
coupon
Then display:
eligible promotions
failed promotions
calculated rewards
stacking result
final total
This lets marketing, engineering, and QA validate behavior before launch.
Explain Deals Clearly to Users
A technically correct promotion can still create a poor user experience if eligibility conditions are difficult to understand.
Consumer-facing resources such as a Smart Shopping Guide can help users approach offers more carefully, but the commerce system itself should also explain the important conditions directly.
For example:
Save $20 when eligible merchandise reaches $100.
Excluded:
Gift cards and subscriptions.
Expires:
November 30.
Clear conditions reduce both customer confusion and support requests.
Treat Promotions as a Domain
Once a commerce system becomes large enough, promotions are no longer a collection of checkout exceptions.
They are their own domain with:
rules
eligibility
rewards
allocation
stacking
redemption
limits
versioning
auditing
refund behavior
Treating them explicitly usually produces a much cleaner architecture.
A Practical Promotion Evaluation Flow
A simplified workflow can look like this:
Load active promotion definitions.
Filter by time and region.
Identify candidate promotions.
Build eligible basket for each promotion.
Evaluate customer rules.
Evaluate product rules.
Evaluate order rules.
Evaluate usage limits.
Calculate potential rewards.
Apply stacking rules.
Select winning promotions.
Reserve limited redemptions where necessary.
Return calculated pricing and eligibility explanations.
Finalize redemption after successful transaction.
Final Thought
Promotions become difficult when business rules are hidden inside application code.
The more campaigns a store runs, the harder that approach becomes to maintain.
Instead:
separate eligibility from reward
represent reusable conditions
store rules as structured data
make exclusions explicit
return failure reasons
version promotion definitions
control stacking
log important decisions
test rule combinations
A promotion engine should not know that marketing is running “Black Friday Deal #27.”
It should understand a set of reusable business rules.
That is what allows the system to support new promotions without turning every campaign into another software deployment.
AI-assisted disclosure: This article was created with AI assistance and reviewed and edited for clarity and accuracy before publication.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.