<?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 Alp Şakacı on Medium]]></title>
        <description><![CDATA[Stories by Alp Şakacı on Medium]]></description>
        <link>https://medium.com/@alpsakaci?source=rss-db49d4b05be0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*L3eO8cLjqDYs-_f6.jpg</url>
            <title>Stories by Alp Şakacı on Medium</title>
            <link>https://medium.com/@alpsakaci?source=rss-db49d4b05be0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 16:58:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alpsakaci/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[Supercharging FastAPI with PyLine Core: A Clean Architecture Approach]]></title>
            <link>https://medium.com/@alpsakaci/supercharging-fastapi-with-pyline-core-a-clean-architecture-approach-b5880ac7a460?source=rss-db49d4b05be0------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5880ac7a460</guid>
            <dc:creator><![CDATA[Alp Şakacı]]></dc:creator>
            <pubDate>Thu, 26 Feb 2026 16:05:17 GMT</pubDate>
            <atom:updated>2026-02-26T16:05:17.637Z</atom:updated>
            <content:encoded><![CDATA[<p>FastAPI has taken the Python backend ecosystem by storm. Thanks to its incredible performance, developer-friendly design, and native support for asynchronous programming, it is the go-to choice for building modern APIs. However, as your FastAPI applications grow in size and complexity, you might start facing a common problem: bloated routers and tightly coupled business logic.</p><p>When your API endpoints are responsible for validating data, triggering database operations, sending emails, and formatting responses, the code becomes difficult to maintain and test. This is where architectural patterns like <strong>CQRS (Command Query Responsibility Segregation)</strong> and <strong>Event-Driven Architecture</strong> shine.</p><p>To make implementing these patterns a breeze in Python, we can integrate FastAPI with <strong>PyLine Core</strong> — a lightweight framework specifically designed for CQRS and Pipeline Orchestration.</p><p>In this article, we’ll explore how to build a clean, scalable, and maintainable FastAPI application using PyLine Core.</p><h3>What is PyLine Core?</h3><p><a href="https://github.com/alpsakaci/pyline">PyLine Core</a> is a lightweight Python framework that brings order to your application’s business logic. It provides core constructs to implement:</p><ul><li><strong>Commands &amp; Handlers:</strong> For write operations that mutate state (e.g., creating a user, updating a post).</li><li><strong>Queries &amp; Handlers:</strong> For read operations that fetch data without altering the state.</li><li><strong>Mediator Pattern:</strong> A central hub to dispatch commands and queries to their respective handlers, decoupling the invoker from the receiver.</li><li><strong>EventBus:</strong> A background event system for handling non-blocking asynchronous tasks (e.g., sending a welcome email after signing up).</li></ul><p>By integrating PyLine into FastAPI, we can completely separate HTTP communication from core application logic.</p><h3>The Architectural Vision</h3><p>Imagine a typical FastAPI route to create a user. Without clean architecture, it might look like this:</p><pre>@router.post(&quot;/users/&quot;)<br>async def create_user(user: UserCreate, db: Session = Depends(get_db)):<br>    # 1. Check if user exists<br>    # 2. Hash password<br>    # 3. Save to database<br>    # 4. Send welcome email (blocking or background task)<br>    # 5. Return response<br>    ...</pre><p>With <strong>PyLine Core</strong>, we shift the responsibility. The router’s only job is to receive the HTTP request and hand off a “Command” to the Mediator.</p><pre>@router.post(&quot;/&quot;)<br>async def create_user(user_in: UserCreate):<br>    command = CreateUserCommand(username=user_in.username, email=user_in.email)<br>    user_id = await mediator.send(command)<br>    return {&quot;id&quot;: user_id, &quot;message&quot;: &quot;User created successfully.&quot;}</pre><p>This is the essence of CQRS: we are sending a command to effectively tell the system “do this”. The router doesn’t need to know <em>how</em> to do it.</p><h3>Structuring the Boilerplate</h3><p>To keep things organized, let’s look at a scalable project structure:</p><pre>app/<br>├── api/<br>│   └── endpoints/        # FastAPI routers (HTTP layer)<br>├── application/          # PyLine integration (CQRS &amp; Events)<br>│   ├── commands/         # Write operations<br>│   ├── queries/          # Read operations<br>│   ├── events/           # Asynchronous events<br>│   └── registry.py       # Handler registration<br>├── core/                 # Config &amp; Settings<br>├── domain/               # Pydantic schemas and models<br>└── main.py               # Application entry point</pre><h3>Step-by-Step Implementation</h3><p>Let’s dive into how we actually build this integration.</p><h3>1. Setting Up the FastAPI Lifespan</h3><p>First, we need to initialize PyLine’s EventBus and register our handlers when the FastAPI application starts. FastAPI&#39;s lifespan context manager is perfect for this:</p><pre>import logging<br>from fastapi import FastAPI<br>from contextlib import asynccontextmanager<br>from app.application.registry import register_handlers<br>from pyline import event_bus</pre><pre>logger = logging.getLogger(__name__)</pre><pre>@asynccontextmanager<br>async def lifespan(app: FastAPI):<br>    # Startup: Register handlers and start event bus<br>    logger.info(&quot;Registering PyLine handlers...&quot;)<br>    register_handlers()<br>    <br>    yield<br>    <br>    # Shutdown: Cleanly shut down EventBus<br>    logger.info(&quot;Shutting down PyLine EventBus...&quot;)<br>    await event_bus.shutdown()</pre><pre>app = FastAPI(title=&quot;FastAPI + PyLine Boilerplate&quot;, lifespan=lifespan)</pre><h3>2. Defining a Query and its Handler</h3><p>Let’s say we want to fetch a user. We define a Query and its associated QueryHandler:</p><pre>from dataclasses import dataclass<br>from typing import Optional<br>from pyline import Query, QueryResult, QueryHandler</pre><pre>@dataclass<br>class GetUserQuery(Query):<br>    user_id: str</pre><pre>@dataclass<br>class GetUserQueryResult(QueryResult):<br>    user: Optional[dict]</pre><pre>class GetUserQueryHandler(QueryHandler):<br>    async def handle(self, query: GetUserQuery) -&gt; GetUserQueryResult:<br>        # Here you would typically use an injected repository or ORM<br>        # to fetch data from the database.<br>        if query.user_id == &quot;not-found&quot;:<br>            return GetUserQueryResult(user=None)<br>        <br>        return GetUserQueryResult(user={<br>            &quot;id&quot;: query.user_id,<br>            &quot;username&quot;: &quot;johndoe&quot;,<br>        })</pre><p>Notice how clean this is? The handler’s sole responsibility is processing this specific read request. It can be easily unit tested in complete isolation from FastAPI.</p><h3>3. Using the Mediator in FastAPI</h3><p>Now, let’s connect our FastAPI endpoint to the GetUserQuery using PyLine&#39;s central mediator.</p><pre>from fastapi import APIRouter, HTTPException<br>from pyline import mediator<br>from app.application.queries.get_user import GetUserQuery</pre><pre>router = APIRouter()</pre><pre>@router.get(&quot;/{user_id}&quot;)<br>async def get_user(user_id: str):<br>    query = GetUserQuery(user_id=user_id)<br>    <br>    # Dispatch query using PyLine&#39;s mediator<br>    query_result = await mediator.send(query)<br>    <br>    if not query_result.user:<br>        raise HTTPException(status_code=404, detail=&quot;User not found&quot;)<br>        <br>    return query_result.user</pre><h3>4. Background Processing with EventBus</h3><p>For write operations logic can be even deeper. When a user is successfully created, we might want to send a welcome email without blocking the HTTP response.</p><p>We can achieve this by having the command handler publish an event to PyLine’s EventBus. Independent Event Handlers will then pick it up in the background.</p><pre>from pyline import Command, CommandHandler, event_bus</pre><pre>@dataclass<br>class CreateUserCommand(Command):<br>    username: str<br>    email: str</pre><pre>class CreateUserCommandHandler(CommandHandler):<br>    async def handle(self, command: CreateUserCommand) -&gt; str:<br>        # 1. Save user to database<br>        user_id = &quot;new-uuid&quot;<br>        <br>        # 2. Publish event to EventBus<br>        event = UserCreatedEvent(user_id=user_id, email=command.email)<br>        await event_bus.publish(event)<br>        <br>        return user_id</pre><p>With this approach, adding new features — like sending a notification to Slack when a new user joins — is as simple as writing a new EventHandler for UserCreatedEvent. The FastAPI endpoint and the Command Handler don&#39;t need to be modified at all.</p><h3>Conclusion</h3><p>By integrating <strong>FastAPI</strong> with <strong>PyLine Core</strong>, we successfully decoupled our HTTP routing from the business rules and background processing logic.</p><p>The key benefits of this approach are:</p><ul><li><strong>Clean Architecture:</strong> Domain and application logic are completely separated from the web framework.</li><li><strong>Extreme Testability:</strong> Handlers can be tested independently with pure mock data without spinning up test web clients.</li><li><strong>Scalability:</strong> Event-driven design makes our application ready for complex background workflows.</li><li><strong>Maintainability:</strong> New features require adding new files (Commands/Queries) rather than bloating existing controllers.</li></ul><p>If you are starting a new FastAPI project and want to ensure it grows elegantly, combining PyLine Core’s CQRS and Event capabilities is an excellent architectural choice.</p><h3>Resources</h3><ul><li><a href="https://github.com/alpsakaci/pyline"><strong>PyLine Core GitHub Repository</strong></a></li><li><a href="https://github.com/alpsakaci/pyline-fastapi"><strong>FastAPI Boilerplate with PyLine</strong></a></li></ul><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5880ac7a460" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unveiling the Breakthrough in Finding Similar Products with Vector Search Across 1 Billion Images]]></title>
            <link>https://medium.com/trendyol-tech/unveiling-the-breakthrough-in-finding-similar-products-with-vector-search-across-1-billion-images-f02fed163130?source=rss-db49d4b05be0------2</link>
            <guid isPermaLink="false">https://medium.com/p/f02fed163130</guid>
            <category><![CDATA[image-classification]]></category>
            <category><![CDATA[vector-search]]></category>
            <category><![CDATA[vector-search-engine]]></category>
            <category><![CDATA[image-similarity]]></category>
            <dc:creator><![CDATA[Alp Şakacı]]></dc:creator>
            <pubDate>Mon, 25 Sep 2023 13:32:52 GMT</pubDate>
            <atom:updated>2023-09-25T13:32:52.942Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*0po_vGm-0fZWqokaLq-kIw.jpeg" /></figure><p>Co-Authors: <a href="https://medium.com/u/51bc817a3d69">Mehmet Sezer</a> <a href="https://medium.com/u/930aa5727a58">Sevcan Doğramacı</a></p><h4>Introduction</h4><p>We use the single catalog system at Trendyol. In principle, a product should be created once and this product should be sold by N different sellers.</p><p>The main responsibility of the Data Quality team is to <strong>find duplicate products and merge them to increase user experience. </strong>This process is called product unification. To achieve this, we use various algorithms and technologies in our team.</p><p>In this article, we will share our image search and comparison experiences in our product unification flow.</p><h4>Our Legacy Image Similarity Flow</h4><p>The unification flow consists of three main steps.</p><ol><li>Finding possible duplicates.<br>In the first step, we perform a search operation using the title of a product which is called the reference product. The search result has N product documents with similar titles. These products are the possible duplicates.</li><li>Text and image similarity scoring.<br>We calculate text and image similarity scores between the reference product and its possible duplicates.</li><li>Merge decision.<br>In the last step, we compare product scores with a threshold value. The threshold value is the minimum similarity score to identify products as duplicates. If the similarity score is above the threshold, the product is identified as duplicate and merged.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2lXbV895eYqoKKVluJr6gw.png" /></figure><p>The image similarity score is one of the most important metrics for identifying duplicate products. To say that two product records are duplicates, the product images must be the same or have very high similarity.</p><p><strong>pHash</strong> (perceptual hash) is an image processing technique that generates a hash/fingerprint of an image, representing its characteristics. This hash value is used to determine the degree of similarity by comparing it with other hash values. We were using pHash to calculate image similarity scores in our legacy product unification process.</p><h4>Advantages of pHash</h4><ul><li>Identifies similarities between images, not just duplicates.</li><li>Easy to use like traditional hashing algorithms.</li><li>Comparisons can be performed quickly and efficiently since a hash can be stored as a string.</li></ul><h4>Disadvantages of pHash</h4><ul><li>Minor adjustments, resizing, or compression can significantly alter hash values and affect the similarity ratio.</li><li>pHash converts images into low-dimensional hash values, which may result in information loss compared to the original data. This could lead to the loss of details and may be inadequate to fully represent all visual information.</li><li>Due to its sensitivity to small differences, pHash may not detect relatively similar images. This can create challenges in distinguishing highly similar content.</li></ul><h4>Why we needed a different solution?</h4><p>While detecting duplicate products, we were searching by product title and then calculated image similarity. The ratio of unrelated products in search results was high. We needed to find more related products.</p><p>Moreover, there are the same products that have very similar but not completely identical images in our catalog. As mentioned above, the similarity sensitivity of pHash can be significantly affected by small changes. Due to these changes, the similarity scores of some duplicate products were below the threshold value, resulting in missing the duplicated products. If we kept the threshold value low, there was a risk of estimating different products as duplicates.</p><p>We preferred the vector search method in order to both increase the accuracy of the similarity score and search with the images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EnrWnPZvkkrVYrPmQG4EoA.png" /><figcaption>The same products with different image resolution and quality. Phash similarity score: <strong>0.742</strong></figcaption></figure><h4>Vector Search</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o0VKArdkjsJ2X3G4Ne5NSA.jpeg" /></figure><p>Vector search is an efficient method for similarity detection which has been very popular recently and it is widely used in fields like machine learning and data mining. This approach allows fast and effective identification of similar data by using vector-based features in a dataset. When a search query is given, it ranks vectors in the dataset based on their similarity to the query vector and returns the best matches. As a result, it provides a powerful tool for detecting similar data and understanding patterns within large datasets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TOT28hpoqA-O48cVCaXjsw.png" /><figcaption>Vector Indexing: Vector of an image saved to DB with image ID.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i1pd_chK5vRZQMmprPzqVg.png" /><figcaption>Vector Searching: Vectors, IDs and scores returned as search result.</figcaption></figure><p>As the Data Quality team, we used this method to perform reverse image searches and calculate image similarity. We worked closely with the Trendyol Data Science team. The Data Science team trained machine learning models using product data. We used the machine learning models to transform images into vectors.</p><h4>Advantages of the vector search</h4><ul><li>Vector-based algorithms have better scalability on large datasets.</li><li>Vectors allow products to be represented with more features, enabling more comprehensive similarity analysis.</li><li>Similarity results are more accurate with vector search.</li></ul><h4>Disadvantages of the vector search</h4><ul><li>Vector-based algorithms may require high computational power. You may need to use GPU.</li><li>Vectors can increase database size and require more system resources.</li><li>Search operation requires transforming the data into an appropriate vector space. This preprocessing may be challenging.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EnrWnPZvkkrVYrPmQG4EoA.png" /><figcaption>The same products with different image resolution and quality. Vector search similarity score: <strong>0.981</strong></figcaption></figure><h4>Our new unification flow with vector search</h4><ol><li>Finding similar products with vector search.<br>At first, we perform vector search operations to get the most similar products. The result has image scores and products.</li><li>Product scoring.<br>In this step, we aggregate product details and the image scores which returned from vector search. After that, we use this data as input to the machine learning model, trained by our Data Science team, to predict duplicate products.</li><li>Merge decision.<br>In the last step, the prediction result is used to determine duplicate products. We run our business logic on products that are predicted as matched.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZUHFBzWJrg8Y1qrD3sv4AQ.png" /></figure><h4>Conclusion</h4><p>By using vector search, we provided the opportunity to search by images in addition to product titles. This allowed us to find more relevant products efficiently. Machine learning models increased the similarity score accuracy and the number of matched products.</p><p>As a result of these improvements, we can query millions of products and find duplicates every day.</p><p>Thank you to the Data Quality and Data Science teams.</p><h4><strong>Are you eager to be part of a dynamic team that loves exploring new technologies and embraces fresh challenges every single day?<br></strong><a href="https://jobs.lever.co/trendyol"><strong>Join us</strong></a><strong> and let’s shape the future together!</strong></h4><p><a href="https://jobs.lever.co/trendyol">Trendyol jobs</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f02fed163130" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/unveiling-the-breakthrough-in-finding-similar-products-with-vector-search-across-1-billion-images-f02fed163130">Unveiling the Breakthrough in Finding Similar Products with Vector Search Across 1 Billion Images</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>