<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kenan Aygören on Medium]]></title>
        <description><![CDATA[Stories by Kenan Aygören on Medium]]></description>
        <link>https://medium.com/@kenanaygren?source=rss-5b19c6f27230------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3UM-hCQahtmoOlw9VijzZQ.jpeg</url>
            <title>Stories by Kenan Aygören on Medium</title>
            <link>https://medium.com/@kenanaygren?source=rss-5b19c6f27230------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 23:10:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kenanaygren/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Optimizing Outbound Stock Synchronization: Empowering External Partners in E-commerce]]></title>
            <link>https://medium.com/trendyol-tech/optimizing-outbound-stock-synchronization-empowering-external-partners-in-e-commerce-40255ed4f674?source=rss-5b19c6f27230------2</link>
            <guid isPermaLink="false">https://medium.com/p/40255ed4f674</guid>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[event-driven-architecture]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Kenan Aygören]]></dc:creator>
            <pubDate>Fri, 06 Dec 2024 09:53:44 GMT</pubDate>
            <atom:updated>2024-12-12T12:33:58.774Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VLzL7UybSRTWJELk2iWaJg.png" /><figcaption>Generated via ChatGPT</figcaption></figure><p>In this article, we will discuss one of today’s biggest challenges: real-time cross-platform stock synchronization, and the effective solution we have developed for this problem.</p><p><em>Special thanks to my coworker </em><a href="https://medium.com/@erdemkopan"><strong><em>Erdem Kopan</em></strong></a><em>, with whom we designed the system and wrote this article together.</em></p><p>Today, e-commerce requires much more than just listing a product online. Instant synchronization of accurate stock information across all platforms is increasingly essential for optimal pricing and a seamless customer experience. Especially if the products are open to both domestic and international sales, it becomes more critical for the system to provide consistent data.</p><p>Trendyol has both private label products and marketplace products. As the Global Platforms team, we make various integrations to list these products on various e-commerce platforms around the world. We localize the products that are suitable for the sales of other e-commerce platforms that we sell on Crossdock in our own databases according to various rules in the most appropriate way. However, managing the processes of stock management, price updates and synchronization of saleable products to the other e-commerce platforms manually or with periodic queries created various operational and technical problems for both platforms and us. In this article, we will explain the problems we faced with our old methods and how we overcame these problems by using Kafka, an event-driven solution.</p><h4>Old Method: Synchronization with Periodic API Queries</h4><p>In the past, when communicating with international platforms, we used to ask them to periodically check product stock and price changes in our system. Each platform would make API calls to our system to query the stock, price and other features of the products and update the data in their catalogs in this way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bYJ7niT30ukRyFXvCJ7M5A.png" /><figcaption>Old Method: All Partners have to query stock data periodically for all products (Green ones are Partners service)</figcaption></figure><p>However, this method caused several major problems:</p><ul><li><strong>High Traffic:</strong> With thousands of products constantly listed on various platforms, the periodic API calls were generating huge data traffic. This was causing performance issues for both the platforms and our systems.</li><li><strong>Time Waste:</strong> Changes in the number of stocks or the price of a product can happen instantly, but platforms were only noticing these changes the next time they were queried or when adding the product to the cart. This led to synchronization delays, and synchronization delays led to a bad front-end experience for the customer. The discrepancy between the stock count seen when browsing the product and the stock count seen when adding it to the cart was a common complaint from customers.</li><li><strong>Poor Customer Experience:</strong> Customers may continue to checkout step thinking that a product is in stock, but the order may be canceled due to outdated stock data.</li><li><strong>Operational Challenges:</strong> In particular, delays in stock updates can lead to inaccurate stock status on platforms, causing customer dissatisfaction. Considering that our platform handles a very large number of products — around eight digits — and receives hundreds of thousands of orders daily, it becomes nearly impossible for e-commerce partners to periodically update stock information for hundreds of thousands of active products. For context, during one of the largest annual sales events, we observed tens of millions of partner-based stock updates in a single day. Even during regular high-traffic periods leading up to major campaigns, millions of updates are made daily. On peak days, relying on periodic stock updates makes it nearly impossible to maintain accurate and up-to-date information.</li></ul><p>Therefore, we realized that we needed to develop a new solution to overcome these problems.</p><h4>The Solution: Transition to an Event-Driven Structure with Kafka</h4><p>At this point, we decided that switching to an event-driven architecture would both increase the efficiency of the system and solve traffic problems. Our solution was an event-driven architecture based on <strong><em>Kafka</em></strong>.</p><p>Kafka is a messaging system that we use very intensively at Trendyol, but if you consider the security concerns, it is not appropriate to connect to them directly from the outside. Since we already do a data localization, we thought that we can trigger our partners every time the stock changes and send this information to our partners.</p><h4>How do we work with Kafka?</h4><p>The stock status of a product can change instantly when an order is realized in our warehouses, in our marketplace pool or on a platform. In addition, since we are integrated with international platforms, we need to feed each platform not the stock information in each warehouse, but the stock information in the warehouses we sell to that region. In our old method, platforms did not know which product’s stock had changed, so they had to constantly query the entire catalog. However, with Kafka, we changed this process as follows:</p><ul><li><strong>Capturing Stock Changes:</strong> When there is any change in the stock of the products (new stock entry, order, return, etc.), these changes are instantly transmitted to our system. We update the relevant record in the Couchbase database that we localize in our own domain.</li><li><strong>Producing Kafka Events:</strong> After the stock change information arrives, this information generates a dcp event from Couchbase. Here, an event is generated on Kafka with the go-dcp connector developed as open source by our teammates at Trendyol. This event contains information such as the stock amount of the relevant product, the reason for the change and the change time.</li></ul><p>Example Kafka Event:</p><pre>{<br>    &quot;id&quot;: &quot;id-1&quot;,<br>    &quot;eventId&quot;: &quot;event-uuid&quot;,<br>    &quot;tenantId&quot;: &quot;PARTNER_49&quot;,<br>    &quot;eventType&quot;: &quot;StockUpdated&quot;,<br>    &quot;url&quot;: &quot;**************&quot;,<br>    &quot;method&quot;: &quot;POST&quot;,<br>    &quot;data&quot;: {<br>        &quot;variantId&quot;: &quot;variant-1&quot;,<br>        &quot;availableQuantity&quot;: 131,<br>        &quot;warehouses&quot;: {<br>            &quot;trendyol&quot;: {<br>                &quot;quantity&quot;: 131,<br>                &quot;tags&quot;: null<br>            },<br>            &quot;seller&quot;: {<br>                &quot;quantity&quot;: 0,<br>                &quot;tags&quot;: null<br>            }<br>        }<br>    }<br>}</pre><ul><li><strong>Subscribe to Platforms:</strong> E-commerce platforms have subscribed to our system via Subscription API. For subscription, we ask them to open an http api with a request and response model as we specify to the api we offer. They need to save the information of the api they open to our api. In this way, they only receive information about the products with stock changes. So they don’t have to scan the whole catalog all the time.</li><li><strong>Instant Update:</strong> The stock information sent to the platform with the Kafka event is immediately processed by the platform and the current stock status of the product is reflected in their system.</li></ul><h4>Advantages of Event-Driven Structure</h4><ul><li><strong>Decreased Traffic:</strong> Now platforms only receive information for products with changes, greatly reducing data traffic by eliminating unnecessary API calls.</li><li><strong>Instant Synchronization:</strong> Instant synchronization of stock changes with platforms eliminates delays, reducing missed orders and improving customer satisfaction.</li><li><strong>Efficiency:</strong> This structure reduced the workload on both their side and ours, as it prevented platforms from having to constantly check stock changes in our system.</li></ul><h4>Technical Details</h4><p>At the center of this solution is <strong><em>Apache Kafka</em></strong>. Kafka, as a distributed event streaming platform, can process high volumes of data in real time and manage data flow effectively. When Kafka events are generated, our workers are triggered and automatically push to e-commerce platforms and process instantly. With this model, platforms can track only the stock changes they are interested in.</p><p>One of the biggest advantages of this structure is that the system is scalable. Even when new platforms are integrated or our product catalog expands, there is no bottleneck in the system thanks to Kafka’s high performance and scalability.</p><h4><strong>System Architecture</strong></h4><p>In our system, we store each product in combination with relevant partner information in our Couchbase database. This data includes product details, prices calculated according to specific rules, and stock information from warehouses where we can fulfill orders for partners. We call this data structure an “Offer”. Essentially, each partner is assumed to have its own set of offers.</p><p>Example Offer Data:</p><pre>{<br>  &quot;id&quot;: &quot;variant-1_partner-1&quot;,<br>  &quot;partnerId&quot;: &quot;partner-1&quot;,<br>  &quot;channelId&quot;: &quot;channel-1&quot;,<br>  &quot;listings&quot;: [<br>    {<br>      &quot;id&quot;: &quot;listing-1&quot;,<br>      &quot;fulfilmentType&quot;: &quot;ST&quot;,<br>      &quot;sellerId&quot;: &quot;seller-1&quot;,<br>      &quot;isActive&quot;: true<br>    }<br>  ],<br>  &quot;stocks&quot;: [<br>    {<br>      &quot;id&quot;: &quot;stock-1&quot;,<br>      &quot;listingId&quot;: &quot;listing-1&quot;,<br>      &quot;availableQuantity&quot;: 131,<br>      &quot;warehouseId&quot;: &quot;wh-1&quot;<br>    },<br>    {<br>      &quot;id&quot;: &quot;stock-2&quot;,<br>      &quot;listingId&quot;: &quot;listing-1&quot;,<br>      &quot;availableQuantity&quot;: 0,<br>      &quot;warehouseId&quot;: &quot;wh-2&quot;<br>    },<br>    {<br>      &quot;id&quot;: &quot;stock-3&quot;,<br>      &quot;listingId&quot;: &quot;listing-1&quot;,<br>      &quot;availableQuantity&quot;: 0,<br>      &quot;warehouseId&quot;: &quot;wh-3&quot;<br>    }<br>  ],<br>  &quot;product&quot;: {<br>    &quot;variantId&quot;: &quot;variant-1&quot;,<br>    &quot;brandId&quot;: &quot;brand-1&quot;,<br>    &quot;barcode&quot;: &quot;barcode-1&quot;,<br>    &quot;modelNo&quot;: &quot;modelNo-1&quot;,<br>    &quot;contentId&quot;: &quot;content-1&quot;,<br>    &quot;gpTags&quot;: null<br>  },<br>  &quot;changedDate&quot;: 1730415560248,<br>  &quot;creationDate&quot;: 1701971527370,<br>  &quot;isActive&quot;: true<br>}</pre><p><strong>Old Architecture:</strong> In the previous architecture, partners had to make API calls to our system to get stock information for each offer.</p><p><strong>New Architecture: </strong>The new architecture works as follows.</p><p><strong><em>Partner API Setup and Registration:</em></strong> First, partners develop an API that adheres to the contracts provided in our documentation. They then register this API’s URL and credentials with our subscription API.</p><p><strong><em>Offer Updates and Kafka Events:</em></strong> As products, prices, or stock levels are updated, the offers change, triggering Kafka events. Specifically, stock updates are published to a Kafka topic named stock.updated.0.</p><p><strong><em>Partner-Offer-Consumer Application:</em></strong> Our partner-offer-consumer application listens to these Kafka events. If a stock change relates to an offer associated with a registered partner, the relevant event is sent to the outbound API.</p><p><strong><em>Outbound API and Event Management:</em> </strong>The outbound API publishes the incoming request to a separate Kafka topic, sets the event status to “in_progress,” and logs it in its database. This database stores details about which URL the event should be sent to and the associated data. These events are then processed by the webhook-worker application, which sends each event in parallel to the specified URLs (the APIs set up by partners for this process).</p><p><strong><em>Updating Delivery Status:</em></strong> Once the partner API responds, the webhook-worker updates the outbound API with the delivery status. If the event is successfully delivered, its status is marked as “done.” For failed deliveries, the status is set to “waiting.”</p><p><strong><em>Retry Mechanism:</em></strong> The outbound-outbox-worker application periodically checks for events in the “waiting” status for subscribed partners and attempts to resend them. This architecture enables our partners to receive real-time stock updates efficiently and reliably, enhancing synchronization and reducing manual checks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HQJZQuEpPuYhTRcKj9y--g.png" /><figcaption>Our event-driven structure and how Kafka is integrated into the system (Green ones are Partners service)</figcaption></figure><h4><strong>Conclusion</strong></h4><p>Implementing the new architecture has significantly improved our operations and partner experiences. By transitioning to an event-driven approach, we reduced API traffic by 85%, as partners now receive updates only when necessary, compared to the previous system where ~10 million monthly API requests were made to check stock levels. Real-time updates have replaced delays of 5–10 minutes, ensuring stock changes are delivered to partners within milliseconds, which minimizes the risk of overselling or underselling. Enhanced synchronization accuracy has reduced order failures by 25%, resulting in a smoother customer experience. Additionally, our Kafka-based solution now handles over 100,000 stock updates per minute with minimal latency, offering seamless scalability to support a growing partner ecosystem. Partners have also reported a 40% improvement in system efficiency, as they no longer need to allocate resources for repeated API polling. These metrics underscore the transformative impact of this architectural shift, benefiting both our processes and our stakeholders.</p><p>This process showed once again how important accurate and up-to-date information is in e-commerce operations. We are currently working on this structure and will continue to integrate more platforms in the future. Our new goal is to develop a similar event-driven structure for price changes and updates to product specifications.</p><p><strong>About Us</strong></p><p>We’re building a team of the brightest minds in our industry. Interested in joining us? Visit the pages below to learn more about our open positions.</p><p><a href="https://careers.trendyol.com/tr">Home - Trendyol Careers</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40255ed4f674" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/optimizing-outbound-stock-synchronization-empowering-external-partners-in-e-commerce-40255ed4f674">Optimizing Outbound Stock Synchronization: Empowering External Partners in E-commerce</a> was originally published in <a href="https://medium.com/trendyol-tech">Trendyol Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>