Trendyol Coupon Journey: Game Changer Collectable Coupons

Metin Barkın Narin
Trendyol Tech
Published in
9 min readAug 18, 2022

This section will take you on a journey about the birth of ‘Collectable Coupons’ that can be collected on Trendyol, their benefits for the customer, and how they are realized and designed. In this way, we will see how the use of coupons for customers increases and how the sales volumes of sellers are increased. We will witness how both stakeholders of the seller and customer, who are part of the game, win together.

We talked about our coupon journey in our previous series. We have 500M active coupons. What about these;

  • How many of the coupons are attractive to users?
  • How many of the coupons reach the target user?
  • Are the coupons reaching the right user?
  • How many of the coupons are used in the order?

There are many metrics that we can observe.

Create numbers, use numbers, order numbers, etc.

The main key point is;
Did all the created coupons meet the right user?

Statistics never say a lie.

In the past, coupon usage was not at the level we wanted, we saw this by looking at the data. These coupons, which Trendyol automatically created according to a certain algorithm. It is seen that could not turn into order because they could not reach the right user.

How has this changed by harnessing the power of data?

It’s very simple by bringing the right coupon with the right user.

By reading the data correctly, we increased the coupon usage 10x.

Hang on to your hat!

How the game has changed, here are the actors :)

1- Follow seller store and win (ie. FollowToWin Coupons)

2- Collect from Product Detail and win

(ie. CollectToWin Coupons with Product Detail Type)

3-Collect from Collectable Coupons Listing page and win

(ie. CollectToWin Coupons with Landing Type)

FollowToWin Coupons

Our Collectable Coupon adventure started with Follow Win coupons. Thanks to our Marketplace structure, we offered sellers the opportunity to earn special coupons for their followers. It was a good start for us and it attracted great attention. In this way, while the number of follow-ups of our marketplace sellers increased, customers made their purchases with the coupons they had.

FollowToWin Coupons

FollowToWin Coupons System Design

FollowToWin Coupons System Design consists of 3 different stages.

  • Create Flow
  • Available Flow
  • Collect Flow

Create FollowToWin Flow

  1. Received FollowToWin Create Request from the seller.
  2. For Coupon Collect API, in order to prepare the FollowToWin Create request, first of all, CouponType and CouponGroup requests are prepared, and create requests are sent to Coupon API.
  3. If the CouponType and CouponGroup requests are valid, the Coupon is saved in the Coupon Couchbase DB and the relevant ids are returned.
  4. Finally, our FollowToWin create request is ready. The relevant request is sent to the Coupon Collect API.
  5. If the FollowToWin create request is valid, the corresponding FollowToWin is created and saved in the Collectable Couchbase DB.
FollowToWin/CollectToWin Create Flow

Available FollowToWin Flow

  1. Other team clients request the ‘you have a follower coupon’ pop-up buttons on the seller detail page with seller and userId.
  2. Looking for Collectable Coupons available for sellerId.
  • If all validations are suitable, the relevant response is returned.
FollowToWin Available Flow

Collect FollowToWin Flow

  1. The client sends the relevant collect request for ‘follow’ clicks on the relevant seller detail page.
  2. It’s finding the Collectable Coupon associated with the sellerId from the request.
  • If the same validations are provided as in the available flow
  • A Create/Update related bucket for userId:collectedId with TTL value of collect-end-date.
  • We write to store this information into the bucket that the user has collected this coupon.
  • The relevant collectable document of the current collect count is increased by one.

3. The related event create and publish on the Kafka topic. Apart from this, the relevant response is returned to the Seller store.

4. The event from the relevant topic is consumed with Coupon Collect Consumer.

5. The related event is converted to Coupon Create Request by Coupon Collect Consumer.

6. Coupon API saves the create request to its DB.

FollowToWin Collect Flow

CollectToWin Coupons

Our Collectable Coupon journeys continued with coupons that can be collected from the product details. Our sellers had the opportunity to create Product Detail coupons for their own products and earn these coupons for customers. In this way, it has been ensured that the sellers' products have more user-friendly coupons. This development increased the use of coupons and had a positive impact on order metrics. Both our customers and our vendors were satisfied with this work and became partners in a successful process where everyone wins. Apart from that, our CRM teams gained the flexibility to be included in these processes. Customers were allowed to be collected by defining a large number of user-friendly coupons for Trendyol Products.

CollectToWin Coupons (Product Detail)
CollectToWin Coupons (Product Detail)

CollectToWin Coupons System Design

Product Detail of System Design consists of 3 different stages.

The system design of CollectToWin Coupons that can be collected from product details consists of 3 stages.

  • Create Flow
  • Indexing Flow
  • Collect Flow

Create CollectToWin Flow

Create stage is almost the same as FollowToWin create stage.

The only difference is adding CollectToWin Type is PRODUCT_DETAIL in the request. Other steps are the same. You can review the above create step again.

Indexing CollectToWin Flow

  1. After the CollectToWin creates a process, the CollectToWin record starts to be listened to by the Collectable Eventing Functions.
  2. For each newly created CollectToWin, the START event is also recorded in the CollectableStateEvent bucket. In addition, the END, CANCEL, and LIMIT_REACHED events are created by listening to the Collectable Eventing Functions. For more information about Couchbase Eventing Functions for our series.
  3. Data from the CollectableStateEvent bucket is retrieved with Kafka Connect Couchbase Connector to relevant Kafka topic. Kafka Connect is a framework to stream data into and out of Apache Kafka. The Confluent Platform ships with several built-in connectors that can be used to stream data to or from commonly used systems such as relational databases or NoSQL.For more information about Kafka Connect. Parallel to this process, the data in the Collectable Couchbase is prepared via Collectable Search and Collectable Content CBES in order to mutate to 2 different ElasticSearches DB. The data prepared by CBES(Couchbase Elastic Search Connectors) for mutate is transferred to Collectable Search and Collectable Content Elasticsearch. Services abbreviated as CBES perform this transfer through Couchbase Elasticsearch Connectors. The Couchbase Elasticsearch Connector replicates your documents from Couchbase Server to Elasticsearch in near real-time. The connector uses the high-performance Database Change Protocol (DCP) to receive notifications when documents change in Couchbase. For more information about Couchbase Elasticsearch connectors.
  4. The data obtained from the CollectableStateEvent Bucket via the Coupon Kafka Connet Couchbase connector(Kafa Connect Couchbase Connector) is published on the relevant topic.
  5. The Collectable Coupon Invalidation Consumer subscribes to the relevant Kafka topic and consumes the data.
  6. Available request is sent to the Collectable Content Api for relevant data.
  7. Contents suitable for collection are searched from Collectable Content Elasticsearch. Hit data is added to the CollectToWinContent list. The created answer is returned to clients.
  8. Product Detail clients send search requests.
  9. Contents suitable for collection are searched from Collectable Search Elasticsearch. Hit data is added to the CollectToWinSearch list. The created answer is returned to clients.” Win” options on the product are drawn in this way.
Indexing Flow

Why Two Different Elasticsearch?

In order to isolate the load on the indexing side and the load on the end-user side, two different Elasticsearch were used.

Single Point of Failure. We store it in a similar data format, the two elastics can be used interchangeably if necessary.

Collect CollectToWin Flow From Product Detail

  1. A request for “collect” clicks is received from the product detail client. The Appropriate CollectToWin is found with the id from the request. Some validations are checked. Then the user’s CollectToWin document is found with the userId. If there is a document, it is checked whether the user has collected the CollectToWin coupon and whether the user limit is sufficient to collect it. A new one is appended to the document. Or the new document is inserted
  2. The CollectToWin document is converted to the relevant event model. Then this event model is published to associate with Kafka's topic.
  3. This event is consumed by Coupon Collect Consumer.
  4. Coupon Collect Consumer converts to coupon create request.
  5. Coupon API saves coupons to Coupon Couchbase from request.
Collect Flow from Product Detail

With the success of Collectable Coupons from Product Detail, we have added another Collectable coupon to the team. These coupons, which can be collected from the Collectable Coupons Listing page at LANDING CollectToWin. Event times, draw great interest from users and run out in seconds. So how did we design these types of coupons?

System design of LANDING CollectToWin Coupons that can be collected from Collectable Coupons Listing pages consists of 3 stages.

  • Create Flow
  • Get Flow
  • Collect Flow

Overall Landing Flow

Unlike other coupons, the creating stage is performed by our CRM teams.

  1. CollectToWin create request is received from CRM. The coupon is sent to Coupon Collect API by adding LANDING option as type.
  2. If the create request is valid, the relevant CollectToWin document is created and saved in the Collectable Couchbase.
  3. Get Landing Request is received from our Landing Clients. Meanwhile, Landing type CollectToWin coupons are cached in an in-memory cache for a period determined by us.
  4. These get requests are executed through the in-memory cache. The cached CollectToWin data is added to the response and transmitted to the client.
  5. CollectToWin coupons in Landing type from the previous response are drawn in a certain order on the Collectable Coupons Listing page. CollectToWin coupons offered to users on this page can be collected with collect requests. Collect flow is executed precisely the same as other collect flows.
Overall Landing Flow

Coming New Features

Coming Soon, our CollecttoWin flow will not only be specific to event times, but will be actively offered to users every day. In this way, users will have coupon pages that they can actively follow.

We are also looking forward to many new features such as Multiple Coupons Usage, Mega Coupons, and Percentage Coupons.

Importance of System Design

During these developments, we also performed refactor operations due to business differences. CollectToWin and FollowToWin, which are also in the same CollectableCoupons bucket, so that business differences do not affect each other. Separates them into separate buckets. Currently, we keep CollectToWin and Landing in the same bucket as a type. Here, too, if the business differs, we can separate it. Therefore, we should use designs that are easy to maintain and open to new features.When you examine the system design we have created, you can see that it is suitable for this.

As a result, the GAME IS CHANGED AND COUPON USAGE INCREASED

In order to achieve this success, we faced many technical problems. So we have used many technologies to solve these problems. System designs include Kafka, Kafka Connect, Elasticsearch, Couchbase, Couchbase Eventing, and many microservices. All have been applied to create this successful domain.

As a result of such developments, a profitable system has been created for both our sellers and our users. The use of coupons has increased, allowing users to buy a product at a discounted price, and for Sellers, more sales figures have been achieved. As seen in the statistics, how the coupons turn into order when they meet the right user is displayed. Usage rates around 0.50–0.00% increase significantly, approaching 10% levels for CollectToWin and FollowToWin.

Data is superpower when used correctly.

Continue to follow and Join us to develop high throughput, scalable, and performance applications. We have a lot of challenges 🚀

Thanks to Baris Ekici, Sefa Can, Anıl Coşar, Caner Yeşildağ, Süleyman Can, Onur Aykaç, Kaan Sönmezöz,Cevat Şentürk and Minaodabas.

Thanks for reading!

--

--

Metin Barkın Narin
Trendyol Tech

Graduated Computer Engineering at Hacettepe University. MSc Seniour Software Engineer at Trendyol.