DEV Community

Cover image for Day 17: Coupon & Promotions Engine - AI System Design in Seconds
Matt Frank
Matt Frank

Posted on

Day 17: Coupon & Promotions Engine - AI System Design in Seconds

Coupon & Promotions Engine: Designing Flexibility Without Breaking Your Cart

Building a promotions engine that handles multiple discount types simultaneously is one of those deceptively complex problems that every e-commerce platform faces. A customer wants to stack their loyalty code, a seasonal promotion, and a BOGO offer all at once, and your system needs to calculate the fairest discount while maintaining business rules and preventing exploitation. Get the architecture wrong, and you're either leaving money on the table or frustrating customers with unexpected checkout surprises.

Architecture Overview

A robust coupon and promotions engine separates concerns into distinct layers: promotion definition, eligibility evaluation, and stacking resolution. At the core, you have a Promotion Service that stores and retrieves promotion metadata (discount type, amount, conditions, priority), an Eligibility Engine that determines which promotions apply to a given cart based on product categories, customer segments, and temporal constraints, and a Stacking Resolver that orchestrates how multiple applicable promotions combine.

The flow typically looks like this: when a user adds items to their cart, the system queries all active promotions and filters them through the Eligibility Engine. Each applicable promotion is ranked by priority and type, then passed to the Stacking Resolver. This component is critical because it enforces business rules like "percentage discounts apply before flat discounts" or "free shipping cannot stack with other free-shipping promos." The resolver calculates the final cart total and returns a breakdown showing which promotions contributed to the final price.

Data consistency is essential here. You'll want a dedicated Promotions Database (or cache layer) that's frequently read but carefully written to, since promotions change often but must be atomic. An event-driven architecture helps too: when a promotion is created or modified, emit an event that invalidates caches and ensures all systems see the same rules. This prevents situations where one service applies an expired promotion while another doesn't.

Key Components

The Promotion Catalog stores all available promotions with their metadata: percentage discounts, fixed amounts, BOGO conditions, free shipping triggers, and bundle requirements. The Eligibility Evaluator checks conditions like minimum cart value, specific product inclusions, customer loyalty tier, geographic restrictions, and time windows. The Stacking Resolver is where the magic happens, applying promotion rules in the correct order to prevent double-discounting and respecting business constraints. Finally, the Audit & Analytics Service logs every promotion applied and calculates ROI and customer behavior patterns.

Design Insight: Handling Promotion Stacking

The key to stacking is establishing a clear precedence model based on business objectives. Most e-commerce platforms use a tiered approach: define stacking groups (loyalty, seasonal, flash sales, free shipping) and specify which groups can combine. Within each group, only the best promotion applies. For example, if a customer qualifies for both a 10% loyalty discount and a 5% flash sale, you apply only the 10% because they're in the same group.

When promotions span multiple groups, you apply them sequentially in a predetermined order, typically percentage discounts first (calculated on the original amount), then fixed-amount discounts, then free-shipping promotions. This prevents the problem where a fixed discount might eliminate eligibility for a percentage-based one. You also track which promotion drove the final discount and validate that the result respects minimum margins and doesn't violate conflicting business rules. Some platforms even offer customers a choice: "We found 3 promotions for your cart, which combination would you prefer?"

Watch the Full Design Process

This architecture was designed in real-time using AI-powered diagramming. Watch how the system evolved as we explored promotion types, stacking complexity, and data flow:

This is Day 17 of our 365-day system design challenge, where we tackle real-world architecture problems that scale.

Try It Yourself

Want to design your own promotions engine or explore variations like region-specific discounts or VIP-only bundles? Head over to InfraSketch and describe your system in plain English. In seconds, you'll have a professional architecture diagram, complete with a design document.

Top comments (0)