My Solution for Design an Online Coupon Service Like Honey with Score: 9/10

by john_chen

System requirements


Functional:

  1. Coupon Aggregation: The system should automatically search and aggregate coupon codes from various sources.
  2. Automatic Application: Apply relevant coupons automatically during the checkout process on partner websites.
  3. Price Comparison: Provide a price-comparison feature to help users find the best deals.
  4. Deal Alerts: Notify users about new deals, discounts, and coupons based on their preferences.
  5. User Authentication: Allow users to create accounts, save preferences, and track their savings.
  6. Rewards Program: Offer a rewards program where users can earn points or cashback for using the service.
  7. Reporting and Analytics: Provide users with reports on their savings, usage statistics, and personalized recommendations.



Non-Functional:

  1. Performance: The system should provide real-time coupon suggestions and apply them quickly during checkout.
  2. Scalability: The platform should be able to handle a large number of users and coupon data.
  3. Security: Implement robust security measures to protect user data, transactions, and sensitive information.
  4. Usability: Ensure the platform is user-friendly, with an intuitive interface for easy navigation.
  5. Reliability: The service should be available 24/7 with minimal downtime.
  6. Compatibility: Support multiple browsers and operating systems for a seamless user experience.




Capacity estimation


Assume approximately 10,000 online stores.


Need to scrap pricing data from each store, including price changes, daily.


Assume each store has an average of 10,000 different items and each item would need storage for name, ID, store name and price. Assuming each field has at most 100 characters limit, then 400 bytes is required to store an item.


so 400 * 10,000 * 10,000 = 40,000,000,000 bytes which is 40 GB.


Based on these calculations, I would use a SQL database such as MySQL since the storage requirements is only 40GB and also because there are different relationship between the data that could be better modelled using SQL relationships.



API design


GetPrices:

Input - Item Name,

Output - Prices of item from various stores for comparison


ApplyCoupon:

Input - Coupon code,

Output - Applied discount


SetDealAlerts:

Input - User preferences,

Output - Deal notifications


GetCoupon:

Input - Item Name,

Output - List of coupons



Database design


We can have the below entities as part of our database design.


Item

  • price
  • name
  • store


Coupon

  • code
  • store
  • item


Store

  • Name


Deal

  • Store
  • Item
  • Coupon



High-level design


Web Application:

The Web Application serves as the user-facing component that enables user interactions, account management, search features, and deal notifications. It acts as the central hub that coordinates communication between various services.


We will be implementing a microservices architecture. Each microservice could handle specific functions such as user authentication, deal notifications, and search features, leading to a more modular and efficient design.


Additionally, we can leverage cloud-based solutions like Amazon Web Services (AWS) or Google Cloud Platform (GCP) for hosting and managing the Web Application to ensure high availability and reliability.



Coupon Service:

The Coupon component scrapes coupon codes from various sources and maintains a coupon database. We could implement a distributed web scraping system. Use tools like Scrapy or BeautifulSoup in combination with a message queue system like RabbitMQ to orchestrate scraping tasks across multiple nodes. By distributing the scraping workload, we can improve performance and scalability. Additionally, utilize caching mechanisms to reduce redundant requests and optimize response times.



Price Comparison Service:

The Price Comparison Engine compares prices across different e-commerce platforms. We could integrate with established price comparison APIs such as PriceAPI or develop custom price scraping scripts. Implement caching mechanisms to store frequently accessed product prices and reduce API calls.



Notification Service:

The Notification Service sends deal alerts, personalized recommendations, and updates to users via various channels. We could implement a multi-channel notification system by utilizing services like SendGrid or Twilio for email and SMS notifications, and leverage Firebase Cloud Messaging for push notifications. Implement user preference settings to allow customization of notification preferences and frequency.





Request flows


  1. Client: Represents the end-user making a request for item information.
  2. Server: Serves as the central component that coordinates communication between different services.
  3. Price Comparison Service: A service responsible for checking prices of the item across different platforms.
  4. Coupon Service: Manages the retrieval of available coupons for the item.
  5. Deal Alert Service: Handles setting up and confirming deal alerts for the item.




Detailed component design


As mentioned, we are using a microservice architecture for scalability and maintenance. Let us explore how we would implement following three services below:


Price Comparison Service


When a user searches for a product on the platform, the Web Application sends a request to the Price Comparison Service with the product details. The Price Comparison Service integrates with APIs provided by various e-commerce platforms to fetch real-time price information for the requested product. The service retrieves prices from multiple online retailers, considering factors like product availability, shipping costs, and discounts. It compares the prices from different platforms and identifies the best deals or lowest prices available for the product. We can also ensure that the service ensures that the price data is normalized and presented in a consistent format for easy comparison.


Another option to get pricing data is using a customer scrapper. This can be implemented using a worker that periodically scapes designated website for data and stores it in our database. This can be implemented using some sort of task scheduler service.


Deal Alert Service


The deal alert service is essentially a notification service. If there's a good deal we can utilize communication mechanisms like web sockets to inform the client on good deals. We can make the notification service multi-channel as well using third party options like firebase for push notification and Twilio for sms notification.


Coupon Service


For real-time coupon code validation, a suitable data structure like a Hash Table can be employed to efficiently store and retrieve coupon details based on unique codes. When a user enters a coupon code, the system can quickly access the corresponding details for validation.


Failure scenarios/bottlenecks


  1. Third-Party API Dependency:
  2. Scenario: The online coupon service heavily relies on external APIs for coupon code retrieval and price comparison. If these APIs experience downtime or service disruptions, the entire system may fail to fetch coupon codes or provide accurate price comparisons.
  3. Bottleneck: Limited control over third-party APIs can result in inconsistent service availability and performance.
  4. Coupon Code Redemption Errors:
  5. Scenario: Incorrect or expired coupon codes applied during checkout can frustrate users and result in failed transactions or billing discrepancies.
  6. Bottleneck: Inaccurate coupon validation logic or outdated coupon databases can impact user experience and trust in the service.


To mitigate some of these failure scenarios we could implement the following:


  1. Implement Circuit Breaker Pattern for API Resilience:
  2. Utilize the Circuit Breaker pattern to handle failures in third-party API calls gracefully. When an API service is unavailable, the circuit breaker opens to prevent further requests, reducing system overload and providing fallback mechanisms.
  3. Coupon Code Verification Mechanism:
  4. We can enhance the coupon validation process by regularly updating the coupon database, verifying code authenticity, and providing real-time status updates on coupon validity. Implement error handling to notify users of invalid or expired codes before checkout.



Future improvements


It would be interesting the dive more into the recommendation engine for deals. We could potentially use machine learning algorithms to enhance our recommendation results.