<?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 Ertuğrul Gamgam on Medium]]></title>
        <description><![CDATA[Stories by Ertuğrul Gamgam on Medium]]></description>
        <link>https://medium.com/@ertugrul-gamgam?source=rss-7faad67539e9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*g4Zz6-Ricdc68TYJ.jpg</url>
            <title>Stories by Ertuğrul Gamgam on Medium</title>
            <link>https://medium.com/@ertugrul-gamgam?source=rss-7faad67539e9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 19:44:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ertugrul-gamgam/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[Ways To Boost Software Development Teams — Part 1]]></title>
            <link>https://medium.com/trendyol-tech/ways-to-boost-software-development-teams-part-1-1874ca7764f5?source=rss-7faad67539e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/1874ca7764f5</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Ertuğrul Gamgam]]></dc:creator>
            <pubDate>Tue, 06 Dec 2022 09:09:07 GMT</pubDate>
            <atom:updated>2023-01-13T08:17:25.297Z</atom:updated>
            <content:encoded><![CDATA[<h3>Ways To Boost Software Development Teams — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*HTpEmH0w4wR9fYozOqJahA.jpeg" /></figure><p>When we try to figure out the secret of successful teams, we will notice that all have a common ingredient, a good culture that allows teams to establish strong relationships and guide them to strengthen their skills.<br>In Trendyol, creating a better culture is one of the major priorities. In this article, as Promotion Team, we will share the following practices we adopt.</p><p>In addition, you can look at <a href="https://medium.com/trendyol-tech/ways-to-boost-software-development-teams-part-2-c05150654887"><strong><em>Ways To Boost Software Development Teams — Part 2</em></strong></a> to check out other practices we apply.</p><ul><li><strong>Onboarding for Colleagues</strong></li><li><strong>1:1 Meetings with Colleagues and Regular Feedback Flow</strong></li><li><strong>GoyGoy — Gaming Hours</strong></li><li><strong>The Bug / Incident Review Meetings</strong></li><li><strong>Pair Programming</strong></li><li><strong>Lunch and Learn</strong></li><li><strong>Code Reading Sessions</strong></li><li><strong>System Design Sessions</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*f_rDn9F70KZwBeflIVw4tQ.png" /></figure><h3>Onboarding for Colleagues</h3><p>Providing essential materials to new colleagues is one of the most critical issues for us so they feel safe and can see the path ahead clearly, cause we believe in the power of first impressions. 🙂</p><p>As part of the onboarding process, we provide practices such as assigning a buddy to a new teammate, making a phone call, and including them in an onboarding schedule for two weeks.</p><p>A teammate, preferably one of our experienced friends, is selected to guide our new friend who will start a job. Buddy will be the first person she applies to in case of any questions or help.</p><p>One week before starting the job, the buddy makes a welcome phone call and provides preliminary information, receives information about whether the necessary tools have reached her, and answers the questions a new teammate wants to ask.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CKGFo9MDS9FcWlv4EG_TLA.png" /></figure><p>In the onboarding schedule, the newcomer ensures that she meets other friends in the team with whom she will work. Also, the introduction of the tools used, the team working order and culture, the meetings held, the team’s goals, and domain information are given. During this process, we encourage our friends to ask questions and get information from their buddies and other teammates.</p><p>As the Promotion team, we have rich domain information and business rules; hence it is one of the priority issues for us to explain the domain logic so newcomers can understand and have an idea of what to do. <br>We provide our new friends with to benefit from the domain diagrams to understand the domain information better. In addition, by doing business Q&amp;A sessions, we refresh our knowledge and seek solutions by sharing domain-related questions.</p><p>We think that we have a stronger team and company culture when we ensure that our new teammates go through the adaptation process as smoothly as possible, with a plan.</p><h3>1:1 Meetings with Colleagues and Regular Feedback Flow</h3><h4>Why should we do 1:1&#39;s?</h4><p>1:1’s help us to establish truth-based relationships between teammates by giving and receiving feedback. Teammates learn each other’s private areas and do not point out personality as a problem source. Colleagues help each other develop their technical and non-technical skills by giving feedback. Trustworthy relationships make people happy and feel like they belong to the team.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*fGsbhxaVVyf3u3Bam-m3-w.jpeg" /></figure><h4>What should we do?</h4><p>Each team member should arrange 1:1 with all teammates at least once a month. Taking notes on a shared document is essential to remind previous notes. Attendees give positive and constructive feedback to each other. They should provide constructive feedback with the STAR technique. If there is no feedback, attendees can ask the following questions to start a conversation.</p><p><em>What am I good at?<br>What can I do better?</em></p><h4>1:1 results for our team</h4><p>Teammates have solid and trustworthy relationships. They feel confident in sharing their ideas, and no one is afraid to make mistakes.</p><h3>GoyGoy — Gaming Hours</h3><h4>What are we doing?</h4><p>We have goy-goy hours every two weeks. In this meeting, and sometimes outside the meeting, team members come together and spend time just for fun. We try to attend this meeting as the whole team, including product owners, developers, and QA’s. There are some games we play regularly, such as codenames, among us, vampires &amp; villagers, gartic.io, car racing games, and so on. We chat with each other when we’re not playing games as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*Od27sWBFnzbJx9e1L4dG5w.jpeg" /></figure><h4>Why is it crucial?</h4><p>Our workload can increase from time to time. For this reason, we take time to reduce work stress and have a good time. In this way, we aim to strengthen our communication inside our team. During the day, we spend most of our time with our teammates, so strong relationships are vital. These meetings help us to know each other better and make working more enjoyable.</p><h3>The Bug / Incident Review Meetings</h3><p>The Bug / Incident Review Meetings are held to understand the problems we encounter more quickly and easily with their root causes and then to offer practical and permanent solutions against them. In these meetings, team members come together to understand the problem. The root causes are examined, and a solution is specified by looking at what action could be taken to prevent this problem. These meetings allow us to investigate issues, find root causes better, and prevent possible problems that may occur in the future by selecting the most optimal solution.<br>When an incident occurs, we immediately meet with the team members to find the source of the problem by examining the alert details and interpreting the incoming logs; after that, we take the necessary action for a solution.<br>We categorize incidents according to the following;</p><p>1 ) <em>Time Interval<br>2 </em>) <em>Cause and Effect<br>3 </em>) <em>Impact Size (Low / Mid / High / Very High)<br>4 ) How could it have been avoided (Test / Alert )<br>5) Category (Code Deployment Problem, Change, etc.)<br>6) Action Status (Fixed, Temporary Fix)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y-DokAB2DNVnc47m8zzBvg.png" /></figure><p>For applications with a very high number of instant users, providing an inconsistent service can cause massive problems and cause financial loss. Hence, time is vital to take action as quickly as possible for any incident. Almost all team members come together to work on a solution and manage this process with less damage demonstrating how essential teamwork is.</p><h3>Pair Programming</h3><p>While working on a task, we generally do pair programming, which is a common practice at Trendyol. At least our two colleagues gather at our team’s Discord server; while one is coding, the other helps and observes her and gives some feedback. This method is so helpful for developers. One developer can gain the other’s perspectives naturally. We discuss how we can complete a task effectively without leaving technical debt during pair programming. In addition, changing the turn of writing code frequently is a practice we adopt because if just one of us codes, others can lose their attention after a while. We’ve observed that if we do a task this way, it’s almost wholly done error-free, the code is cleaner, and we’re more productive. Furthermore, pair programming is helpful for our new teammates to adapt to our team, business-domain logic, and tech stack.</p><h3>Lunch and Learn</h3><h4>What is L&amp;L?</h4><p>Lunch and learn is when a teammate makes an interactive presentation based on her previous experiences or research on a subject she is good at, curious about, or developing areas of the team. In addition to the meetups everyone can attend in the company, we make lunch and learn presentations within the team. The topic can be something other than software. The primary purpose is to enrich the knowledge of the team. It usually takes between 30–60 minutes. Typically the L&amp;L presentation is done during lunch. However, we do it when the team is convenient.</p><h4>Why should we do a Lunch and Learn presentation? What are the benefits?</h4><p>It increases the spread of knowledge within the team. It supports the presenter in improving on the relevant subject. While the people who know the subject will master more, those who have yet to gain experience with it will have an idea about the topic. L&amp;L develops the presentation and public speaking skills of the presenter as well.</p><h3>Code Reading Sessions</h3><p>In this session, we usually choose an external or an internal project each week and start reading the code. We aimed to learn various implementation examples from these projects and how to use these patterns in our project. For example, one week, we can choose to read the Checkout API code to see how and in which way they implement their tactical DDD patterns. The following week we can choose Golang implementation examples from external sources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8YrCV_KNP30H9vLy0ad6jQ.jpeg" /></figure><h3>System Design Sessions</h3><p>System design sessions aim to strengthen the team’s knowledge of software architecture and their ability to clarify problems and resolve conflicts. It can be designing a news feed system, google maps, a dating app, etc. The good part of these sessions is being interactive.<br>We are opening a board on an online board tool(like Miro, Lucidchart, etc.), and everyone is joining the board to change it. Participants consider the pros and cons of the ideas, for example, Why should we use a graph database? Is eventual consistency acceptable, or do we need strong consistency for this system?</p><p>Every session has a moderator who is responsible for managing the session. When participants ask questions to clarify a problem or resolve ambiguity, the moderator must answer these questions and define requirements. The other responsibility of the moderator is to prepare a small presentation before the session. This presentation should include topics that are related to the system we design. If we develop a chat system, the moderator can talk about pooling, long polling, and web sockets, or if we create a URL shortening, talking about hashing and encoding can be a good choice.</p><p><em>Thanks to </em><a href="https://medium.com/u/d22e5cfef89e">MUSTAFA AKILLI</a>, <a href="https://medium.com/u/5b8c9f5e089c">Oğuzhan Sarıçin</a>, <a href="https://medium.com/u/dbb8df901d4a">Kubra Cakir</a>, <a href="https://medium.com/u/790354e895b5">Selay Arkun</a>, <a href="https://medium.com/u/4968a2788dd5">Sefa Fatihhan Okumuş</a>, <a href="https://medium.com/u/986087db7d99">Emel Serengil</a>, <a href="https://medium.com/u/5a3b8e730252">Ferhaterdas</a>, <a href="https://medium.com/u/60433054d927">Mehmet Aran</a>, <a href="https://medium.com/u/79a08f017ceb">Bilge Tekkursun</a> <em>for their contribution.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1874ca7764f5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/ways-to-boost-software-development-teams-part-1-1874ca7764f5">Ways To Boost Software Development Teams — Part 1</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>
        <item>
            <title><![CDATA[Evolution of Promotion Search at Trendyol]]></title>
            <link>https://medium.com/trendyol-tech/evolution-of-promotion-search-at-trendyol-34570f0e06cb?source=rss-7faad67539e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/34570f0e06cb</guid>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[event-driven-architecture]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[trendyol]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Ertuğrul Gamgam]]></dc:creator>
            <pubDate>Tue, 28 Sep 2021 10:42:33 GMT</pubDate>
            <atom:updated>2021-09-29T17:24:56.075Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Scwb7L27DziQNRT35N1VJw.png" /></figure><p>Promotions are the discount that is applied to the shopping cart. When you modify the contents of your shopping cart (add a new item, remove an item, increase the number of items in your cart, etc. ), promotions should recalculate. A promotion search process is also required before recalculation to identify related promotions with a shopping cart. In this one, I’ll talk about how promotion searching has changed at Trendyol in the last two years.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*7fBeOKoHBlU7zcb6jA_6YQ.jpeg" /><figcaption>Applied Promotions to the Shopping Cart</figcaption></figure><p>In 2019, Promotions used to be calculated by Legacy Promotion API. It was a .Net Framework Application that working on IIS. It fetched all promotions periodically from Trendyol DB and cached promotions as in-memory. After that when a promotion computation was required, Legacy Promotion API was searching the promotions that are relevant to shopping cart from its memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*LNezaEVKMOSKlJTA_dX3vw.jpeg" /></figure><h3>The Problems We Encountered with Legacy Promotion API</h3><h4><strong>Scalability</strong></h4><p>When we wanted to scale Legacy Promotion API we had to deploy it to new IIS machines. Regrettably, this is not an easy task. New machines should be set up and then Legacy Promotion API should be deployed via Octopus. This necessitated a lot of manual labor. I recall that for 2019 Black Friday, we scaled apps that working on Kubernetes in 5 seconds but for Legacy Promotion API, we spent our three days.</p><h4><strong>Issues with a Legacy Code Base</strong></h4><p>Legacy Promotion API had a messy codebase. It was part of a monolith system that was developed before Trendyol Tech started to apply extreme programming practices and microservices. It didn’t have enough reliable tests too.</p><h4><strong>Shared Database</strong></h4><p>Legacy Promotion API was using a shared database called Trendyol DB. This database was also used by nearly all Trendyol legacy apps. Trendyol DB had a huge load and when an issue occurred on Trendyol DB, it also was affecting Legacy Promotion API.</p><h3>Replatforming</h3><p>2019 was the replatforming year for Trendyol Tech. So we began to replatform Legacy Promotion API. After many spikes and performance tests, we came up with the following system design:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MKe4xs-jmJZ6WvPst0MVWw.jpeg" /></figure><h4><strong>Promotion Search API (PSA)</strong></h4><p>When we were designing the original system we did spikes with different programming languages and different search algorithms. We picked Golang because of the performance of the Go spike. We also stuck with a brute force algorithm because more complex data structures and algorithms did not bring a huge performance advantage compared to the complexity they brought. We decided to postpone optimizing the search algorithm until we need it.</p><p>This application is responsible for promotion searching. PSA periodically retrieves all promotions from Promotion DB and cached promotions as in-memory. When PSA receives a search request, it finds related promotions from its memory. Additionally, PSA has a response time of roughly a millisecond.</p><h4>Promotion API</h4><p>Promotion API is a Java Spring Boot application that satisfy core business. Because of complexity of business rules we have implemented domain driven design with a OOP language for Promotion API. OOP language was a better fit for a domain driven design. Main responsibility of Promotion API is to calculate discounts on the shopping cart. In addition, many CRUD operations are executed by Promotion API. For this design, response time of Promotion API is round 8 milliseconds.</p><h4><strong>How This System Works</strong></h4><p>Promotion API calls PSA by sending shopping cart in the request body and PSA returns promotions applicable to the shopping cart. Finally, Promotion API calculates the possible combinations of promotions applied and picks the one that is most advantageous for the customer. If you want to learn more about how this calculation works click <a href="https://medium.com/trendyol-tech/how-do-we-calculate-promotions-in-the-cart-85e7b50af2b6">here</a>.</p><h4><strong>Changing PSA Search Strategy</strong></h4><p>This design worked grate with about 5000 promotions. PSA cached all promotions in an array like below and searched promotion as brute force in a loop.</p><pre>type Cache struct {<br>   Promotions    []Promotion<br>}</pre><p>Unfortunately, because of the newly adopted business model that brought 12x promotions to the system, PSA response time increased about 7ms too and it showed us it will not scale horizontally. We did not waste any time and performed a load test. The performance of the services was not acceptable for us. Worse, there was a huge event two weeks later and PSA had to work more efficiently.</p><p>Fortunately, we were able to rapidly find a solution. Promotions can be created with fifteen different conditions and promotions can have more than one condition. But we realized that lots of promotions included sellerId and campaignId conditions. So, We decided that indexing promotions by sellerId and campaignId with a hash map. Finally, the promotion cache struct appeared as follows:</p><pre>type Cache struct {<br>   SellerPromotions   map[int64][]Promotion<br>   CampaignPromotions map[int64][]Promotion<br>   OtherPromotions    []Promotion<br>}</pre><p>Anymore, brute force searching wasn’t required. PSA was getting promotion lists by sellerId and campaignId of items from cache and then it was finding promotions applicable to the shopping cart. As a result of this development, response time of PSA decreased to around a millisecond again.</p><p>Promotion searching worked with this design at 2020 Black Friday and it successfully received 400k requests per minute. Its average response time was 20ms at the peak point.</p><h4><strong>Many More Promotions</strong></h4><p>In the third quarter of 2020, we have developed a promotion creation page for the sellers. After this development, the count of promotions increased rapidly. The database was storing 1.5 million promotions when I wrote this article. ​It means that in just two years, promotion count increased from 5k to 1.5m ( 300x data ).</p><p>As a result of this increase, some problems occurred on PSA. Firstly, refreshing PSA cache was taking too much time. Also when we scale out PSA ( increasing the number of pods on k8s), all PSA instances were caused much load on replica nodes of Promotion DB and this was a bottleneck to scale PSA. As a result, we made the decision to kill PSA until the 2021 Black Friday and we needed to find an alternative solution.</p><h4><strong>Elasticsearch</strong></h4><p>After lots of tests, we decided to try Elasticsearch to search promotions. But first of all, we needed a solution to feed data to Elasticsearch and manage reindexing process. Also it should be possible changing data model on Elasticsearch during reindexing.</p><p>We decided to use Couchbase Elasticsearch Connector ( CBES ) and deploy it to Kubernetes.</p><p><em>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. </em>You can reach CBES repository <a href="https://github.com/couchbase/couchbase-elasticsearch-connector">here</a>.</p><p>But data of promotions are stored on SQL Server. So firstly we should feed promotions data to Couchbase. Fortunately, Promotion API are producing promotion created-updated events to Kafka. So, We developed a consumer app that consumes these events and writes data of promotions to Couchbase.</p><p>But old promotion created-updated events did not exist on Kafka. So we also wrote a migration app that migrated promotion data from SQL Server to Couchbase once.</p><p>The final design is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6fQsgsvRyAtBFcIkNTcdcQ.jpeg" /><figcaption>Data Feed to Couchbase</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3nF94XOs_2zKgULFu-_80g.jpeg" /><figcaption>Promotion Search with Elasticsearch</figcaption></figure><p>It’s worth noting that CBES doesn’t feed data to Elasticsearch as same as schema on Couchbase. We made some changes on CBES codebase to makes the schema more convenient for searching. This gives us great flexibility. If the search schema needs to be changed in the future, We just make some changes on the code base of CBES and feed data to a new Elasticsearch index with a new CBES instance.</p><h4><strong>Managing Reindexing With CBES</strong></h4><p>Reindexing may be necessary at times. We may want to change the schema of data or configuration changes may be required for the index of Elasticsearch. We manage this process like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ENcJmj7GDXjySGty93Nawg.jpeg" /><figcaption>Reindexing</figcaption></figure><p>New CBES instances start to feed data from Couchbase to a new index. Meanwhile, old CBES instances continue to feed to old index too. Promotion API uses an Elasticsearch alias which refers to the index of promotions. When all of available data is fed to the new index, We change index of alias refer. After this process, Promotion API starts to search promotions via new index.</p><h4><strong>Test</strong></h4><p>Lots of unit, integration, and acceptance tests were written during the development of this system. But promotion calculation is a sensitive area, so we did some additional tests on the production environment too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r3q979BPEXdq6jrgO-zyIQ.jpeg" /></figure><p>When the development was completed, Promotion API was sending parallel requests to both Elasticsearch and PSA and compared the results. On the other hand, discounts were calculated with the response of PSA. If a difference existed, It logged this difference and an alert message was sent to Slack by Kibana. Furthermore, this progress wasn’t running for all users. The last two digits of userId were used to identify test participants. If this logic was disabled for the user, Promotion API only sent a request to PSA. Additionally, this logic might be enabled for specific userIds. We followed these logs for about a month.</p><p>After that Promotion API continued to comparing responses for test users but discounts were calculated with the response of Elasticsearch. Finally, following the logs and observing the whole ordering process for a long time, we took down PSA.</p><h4>Result</h4><p>Promotion API reached 1.6 million rpm in our most recent load test ( 4x load of 2020 Black Friday ). We made many performance optimizations on Elasticsearch and 1.6m rpm is just for one datacenter. Also, Promotion API is running on two different data centers. In my future articles, I will mention how Promotion API runs on two different datacenters and what kind of performance optimization we did for Elasticsearch.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34570f0e06cb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/evolution-of-promotion-search-at-trendyol-34570f0e06cb">Evolution of Promotion Search at Trendyol</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>
        <item>
            <title><![CDATA[Generating Millions of Promotion Codes]]></title>
            <link>https://medium.com/trendyol-tech/generating-million-of-promotion-codes-5e4e0def54d7?source=rss-7faad67539e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e4e0def54d7</guid>
            <category><![CDATA[maintainability]]></category>
            <category><![CDATA[reliability]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[fault-tolerance]]></category>
            <category><![CDATA[scalability]]></category>
            <dc:creator><![CDATA[Ertuğrul Gamgam]]></dc:creator>
            <pubDate>Mon, 24 May 2021 08:12:54 GMT</pubDate>
            <atom:updated>2021-06-02T10:25:54.008Z</atom:updated>
            <content:encoded><![CDATA[<p>As Promotion Team, one of our responsibilities is to provide a system that generates unique promotion codes. In this article, I will talk about the design of this system as well as the scalability and fault tolerance aspects.</p><h4>Promotion</h4><p>Promotions are the discount that is applied to the shopping cart. In addition, promotion can be created with a variety of conditions such as brand, category, seller, etc. My goal in this article is not to talk about the details of the promotion service and how it applies discounts to the shopping cart. You can find more about it in my colleague’s <a href="https://medium.com/trendyol-tech/how-do-we-calculate-promotions-in-the-cart-85e7b50af2b6">article</a>. You may also listen to our Promotion &amp; Coupon podcast <a href="https://open.spotify.com/episode/5vrDf2oV56iJow35EOm4m2?si=fdinv0nSREqUnfWL_PPIfg">here</a>.</p><h4>Code</h4><p>A promotion code needs to be provided by customer to be applied, but for us it is just another condition for the promotion apply logic. When users enter a code, a promotion that is related to the code is applied to the shopping cart by Promotion API. A promotion code can be generated as unique or it can be defined by the user who creates promotion. For example, MEGADETH21 can be defined as a promotion code by the user.</p><p>It could be required to generate millions of unique code for some promotions and a code is corresponding to a row on SQL Server. This row contains id, promotionId, code, maxUsageCount and currentUsageCount columns. We have to be sure that the desired number of codes have been generated. Of course, a solution could be possible like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09e53cf5eb404988d74e757159df5abc/href">https://medium.com/media/09e53cf5eb404988d74e757159df5abc/href</a></iframe><p>Let’s have a look at this solution from the standpoint of fault tolerance. Our application runs on Kubernetes. While creating codes, the database may be down or some network disruption between Kubernetes nodes and database may be happened. As software engineers, we are trying to develop reliable systems in an unreliable world so we must consider all possible scenarios. Unfortunately, designing 100% reliable system is impossible but we should handle faults as much as possible. Another important consideration is scalability. We assume that everything works great but a solution like the above is still unacceptable because of scalability. As I said before we need to generate millions of promotion codes and our system should deliver codes as fast as possible. If the system just needs to generate a few thousand unique codes, probably this solution meets our requirements. But in order to generate millions of unique codes, this solution doesn’t meet business requirements. Nobody wants to wait for hours.</p><h4>Architecture</h4><p>Let’s have a look at the our architecture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MYJ3-ZCOQx-YcJVAxT65ag.jpeg" /></figure><ol><li>To create a promotion with unique codes, send a request to the promotion API.</li><li>Firstly Promotion API checks the count of codes to be generated. Secondly, it creates events based on this count. I’ll demonstrate this with an example. Promotion API has a <em>batchCodeCount</em> config. <em>(count of codes to be generated / batchCodeCount) +1</em> equals the number of events. ( +1 for remaining if it exist). We assume that 5 million unique codes generation is requested to Promotion API and <em>batchCodeCount</em> config equal to 50 thousand. In this case, Promotion API generates 1000 events, each with the following body:</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a9fe5145684d2da90b7c960b155576b/href">https://medium.com/media/7a9fe5145684d2da90b7c960b155576b/href</a></iframe><p>In this body, <em>codeCount</em> indicates that how many codes should be generated for this event and <em>promotionId</em> indicate that codes should be generated for which promotion. Finally, Promotion API produces events to Kafka.</p><p>3. Instances of Promotion Code Generator consume events.</p><p>4. Promotion Code Generator sends as many requests as <em>codeCount</em> to Promotion API then a unique code is generated for each request by Promotion API.</p><p>With this solution, we have a scalable system. If we want to speed up code generation, we can scale horizontally Promotion API and Promotion Code Generator. Additionally, we can increase the partition number of the topic and decrease <em>batchCodeCount</em><strong> </strong>config to speed up code generation<strong>. </strong>When we decrease <em>batchCodeCount</em><strong> </strong>config, Promotion API will generate more events. In this way, more code can be generated simultaneously. Of course, even for this design, scale is limited. The database is under more load during we speed up code generation and it is going to be a bottleneck soon or later.</p><p>There is a big problem which we have to struggle with this design. A fault may occur during Promotion Code Generator sends requests to Promotion API. If this happened, a missing number of codes are generated. So our system needs to handle this.</p><p>We handling this situation like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_4exbEBcjb6KphVP84phnQ.jpeg" /></figure><ol><li>When a fault occurs, Promotion Code Generator produces an event to error topic. The event produced by Code Generator Consumer has the same scheme as the event produced by Promotion API. But the value of <em>codeCount</em> will be different. If Promotion Code Generator consumes an event that codeCount is 50 thousand and a fault occurred after it sends 10 thousand requests to Promotion API then it stops to request to Promotion API and produces an event that codeCount is 40 thousand to error topic. Body of this event like following:</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87691e213c41074a85952977981dfab8/href">https://medium.com/media/87691e213c41074a85952977981dfab8/href</a></iframe><p>2. Kafka Shovel is responsible for moving events between topics. It runs every 5 minutes and moves events from error topic to retry topic. It also adds a retry count to the event header. Each time an event is moved from error topic to retry topic, retry count is increased by 1. If retry could is 5, Kafka Shovel doesn’t move that event. This <a href="https://medium.com/trendyol-tech/kafka-shovel-processing-in-trendyol-order-management-cb28b69547b4">article</a> contains further information about Kafka Shovel. Kafka Shovel’s source code is also available <a href="https://github.com/Trendyol/kafka-shovel">here</a>.</p><p>3. Promotion Code Generator consumes events from the retry topic and continues sending requests to Promotion API.</p><p>I hope you like the article. See you next one 🙂</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e4e0def54d7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/generating-million-of-promotion-codes-5e4e0def54d7">Generating Millions of Promotion Codes</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>
        <item>
            <title><![CDATA[Accelerate to Survive]]></title>
            <link>https://medium.com/trendyol-tech/accelerate-to-survive-d0afccecf4dc?source=rss-7faad67539e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0afccecf4dc</guid>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[trendyol]]></category>
            <category><![CDATA[continuous-development]]></category>
            <category><![CDATA[accelerate]]></category>
            <category><![CDATA[continuous-delivery]]></category>
            <dc:creator><![CDATA[Ertuğrul Gamgam]]></dc:creator>
            <pubDate>Sat, 25 Jul 2020 19:23:29 GMT</pubDate>
            <atom:updated>2020-08-04T19:42:25.361Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*TqUthx9OnORrSvA_aqaVaA.jpeg" /></figure><p>In Trendyol Tech, we are considering about how to improve software delivery performance as much as how to improve software quality. While improving our software delivery process, the book called “Accelerate” is one of the most important guides for us.</p><p>In this article, First I will talk about what is described in Accelerate and then I will briefly talk about what we are doing to accelerate the software delivery.</p><h4>Measuring Software Delivery Performance</h4><p>The performance of software development teams is measured in different ways. However while doing this, many organizations use wrong criteria. For example, one of the most common incorrect criteria is velocity. Each team can assign different point to a story and teams game point of stories when velocity used as a performance criteria. Therefore, it is a misleading criteria for performance measurement.</p><p>Software delivery performance can be evaluated on four key metrics: delivery lead time, deployment frequency, time to restore and change fail rate.</p><p>Lead time is the time until an incoming request is satisfied. When the delivery time is short, we can get feedback from customers faster. Thus, we can make corrections in our applications faster. It will also be easier to identify and solve problems. If we want to reduce the delivery time, we must split stories into small pieces. Moreover, it is going to reduce the error rates. Therefore, how to make sure that our stories are small enough? At this point, deployment frequency helps us. If we deploy our applications frequently, it means that we achieve to split stories into small pieces enough.</p><p>Lead time and deployment frequency are metrics for measured software delivery tempo. If we want to measure stability, we need to focus on time to restore and change fail rate.</p><p>Time to restore is the time that takes to restore a service when an incident is occurred. The change failure rate is a measure of how often deployment failures occur. In other words, it represents how often software, infrastructure or configuration changes fail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ACJ0HTzCO_pxD0m_5O0Fag.png" /><figcaption>Accelerate(Table 2.3)</figcaption></figure><h4>Team Culture</h4><p>Team culture has a significant impact on software delivery performance. In a team with a good culture, people will be more satisfied with their work. First of all, teams must have a culture that focuses on their goals. If so how can organizations improve their team culture?</p><ul><li>Information flow should be provided quickly and reliably.</li><li>People should trust each other and work collaboratively.</li><li>Qualified culture require higher quality decision making. But those decisions are more easily reversed if they turn out to be wrong.</li><li>One person should not be held responsible for failures.</li><li>New ideas should be welcomed.</li><li>Responsibilities should be shared.</li></ul><h4>Continuous Delivery</h4><p>Continuous delivery is a set of capabilities that enable the rapid and reliable software delivery process. Teams that implements CD practices experience less deployment pain and burnout. In addition to this they also have better culture and they reduce rework or unplanned work. There are five primary principles for continuous delivery.</p><ol><li>Build quality in; organizations should invest in teams and the tools they use. In this way, dealing with problems will be faster and it will cost cheaper.</li><li>Work in small batches; teams generally tend to keep the scope of the work large. When we divide the work into small pieces, we can see the impact faster.</li><li>Computers perform repetitive task, people solve problems; Repeated works should be automated. Thus, teams can focus on solving problems and they can invest more in their system.</li><li>The most remarkable feature of high performance teams is that they are never satisfied. They constantly strive to improve their system.</li><li>Everyone is responsible: Different people take part in different stages of the software delivery process. Everyone involved in the process should act in close cooperation.</li></ol><p>We need to establish some basics well to be able to implement continuous delivery. Unfortunately many software development teams work with long running branches. Merging all these branches can be tiring because of conflicts. Hence, our branches should have a short lifetime. If we want to achieve this, we must split stories into small pieces. Furthermore, after each merge, pipelines should be triggered and run tests. Developers should be notified immediately if tests fail.</p><p>Teams that have reliable test automations can work more confidently. In addition, tests make it easier to to determine where we have errors in our code. Developers should maintain acceptance test and fix them. When developers maintain acceptance tests, two important benefits arise. Firstly, code become more testable. Furthermore, it proves to us how important TDD is. Secondly, when developers are responsible for the automation tests, they put in more effort to maintain and fix them.</p><h4>Architecture</h4><p>For a powerful architecture, we should focus on a loosely coupled system. When our system is loosely coupled, we can do our tests without requiring an integrated environment and we can deploy applications independently of other applications it depends on.</p><p>If an organization has a good architecture, communication between the teams is less necessary. In other words, when architecture is loosely coupled, teams are also loosely coupled. Thus, independently of other teams, we can work on our assignment. But it does not mean that there should be no communication between teams. However, too much communication and too many meetings affect delivery performance negatively.</p><p>Also teams should not be forced to use a programming language or tool. They should be free to make their choices according to their needs. In this way, they can do their job with more satisfaction and fun.</p><h4>Deployment Pain</h4><p>Fear of teams during a deployment tells us a lot about delivery performance of a team. Deployment pain specify that teams need to improve their culture and software delivery performance. Too much deployment pain indicates that software development and delivery are not sustainable.</p><p>We should have comprehensive test and deployment automations to reduce deployment pain. Also applying trunk based development practices and having loosely coupled architecture helps us to reduce it. We need to pay attention to deployability while we are writing our code.</p><h4>Burnout</h4><p>Burnout is defined as a physical and mental fatigue caused by overwork and stress. Organizations must prevent team burnout to speed up software delivery process. Because burnout makes us see our work insignificant and it creates a feeling of desperation.</p><p><strong>Common Problems That Can Lead To Burnout</strong></p><p>• Work overload: job demands exceed human limits.</p><p>• Lack of control: inability to influence decisions that affect your job.</p><p>• Insufficient rewards: insufficient financial, institutional, or social rewards.</p><p>• Absence of fairness: lack of fairness in decision-making processes.</p><p>• Value conflicts: mismatch in organizational values and the individual’s values.</p><p><strong>How to Prevent Burnout</strong></p><p>• Fostering a respectful, supportive work environment that emphasizes learning from failures rather than blaming.</p><p>• Communicating a strong sense of purpose.</p><p>• Investing in employee development.</p><p>• Asking employees what is preventing them from achieving their objectives and then fixing those things.</p><p>• Giving employees time, space, and resources to experiment and learn.</p><h4>Leaders</h4><p>Leaders should help their teams to improve their delivery process performance. They should also inspire and motivate their employees.</p><p><strong>How leaders can invest in their teams?</strong></p><p>• Create space and opportunities for learning and improving.</p><p>• Establish a dedicated training budget and make sure people know about it.</p><p>• Encourage staff to attend technical conferences at least once a year and summarize what they learned from that experience.</p><p>• Encourage teams to organize internal events where teams get together to work on technical debt.</p><p>• Set up internal hack days, where cross-functional teams can get together to work on a project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B_XuPBD-jfziSv-owQHb9Q.jpeg" /><figcaption>Trendyol Hack Fest 2019</figcaption></figure><h4>What Are We Doing to Accelerate?</h4><h4>Pipelines</h4><p>We imported all git repositories to GitLab and started using GitLab CI / CD. When a code is merged to the master branch; unit tests, automation tests and sonar analysis are being triggered on pipeline. When a step in the pipeline fails, it sends a notification to the slack channel.</p><h4>Lunch and Learn</h4><p>We organize lunch and learn events in the team regularly. Thus, all of our team members support each other to learn new things.</p><h4>Detect Repetitive Tasks</h4><p>We detected our repetitive tasks and started automating them. Hence, we had more time to solve the problems.</p><h4>Code Reviews</h4><p>By organizing code reviews, we talk about how to improve our code quality. In this way, we make our code more readable and maintainable.</p><h4>Four Key Metrics</h4><p>We are making a Grafana Dashboard to follow four key metrics. (delivery lead time, deployment frequency, time to restore, change fail rate).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0afccecf4dc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/accelerate-to-survive-d0afccecf4dc">Accelerate to Survive</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>
        <item>
            <title><![CDATA[Forwarding Kubernetes Container’s Logs to Elasticsearch with Fluent Bit and Showing Logs with…]]></title>
            <link>https://medium.com/trendyol-tech/forwarding-kubernetes-containers-logs-to-elasticsearch-with-fluent-bit-and-showing-logs-with-411587e54e22?source=rss-7faad67539e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/411587e54e22</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[net-core]]></category>
            <category><![CDATA[fluentbit]]></category>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Ertuğrul Gamgam]]></dc:creator>
            <pubDate>Sat, 14 Dec 2019 12:19:21 GMT</pubDate>
            <atom:updated>2019-12-16T19:11:24.204Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Forwarding Kubernetes Container’s Logs to Elasticsearch with Fluent Bit and Showing Logs with Kibana</strong></h3><p>In this one, I mention how a container forwards its logs to Elasticsearch with Fluent Bit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*AB00t-sTW1v0Rky3UY5TGA.png" /></figure><p><strong>What is Fluent Bit?</strong></p><p>Fluent Bit is a tool that processes and forwards logs. It processes data and forwards them to output. As you can see in the picture, it supports many kinds of inputs and outputs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jm7cAs5_hHe68Qzax2U8Pg.png" /></figure><p>The main topic that I explain in this story is how to collect logs from log files and how to direct them to Elasticsearch.</p><p><strong>Why should I prefer to use logs forwarder even I can get my application’s logs in any way?</strong></p><p>The Twelve-Factor App Methodology explains that perfectly. This methodology shows us how to build our applications in the modern era. According to Twelve-Factor methodology, forwarding logs and storage them are not supposed to be a part of our applications. The only responsibility of our applications must be sent logs to stdout. After that, these logs must be written in a file by the execution environment and deliver them to the final destination by log forwarders. This log management is going to give us pretty much advantages. Let’s say we decided to send out applications logs to another final destination instead of Elasticsearch. In this kind of situation, the only thing we need to do is make some changes in the output config of our log forwarders. Then, our applications are not going to realize that. With using a log forwarder, we provide to our applications not being bothered by unnecessary responsibilities.</p><p><a href="https://12factor.net/logs"><em>https://12factor.net/logs</em></a></p><p><strong>Why Fluent Bit?</strong></p><p>Of course, Every tool has advantages and disadvantages. The ability to work in Kubernetes environment with perfect harmony, being light-weight, and not to require complex configs are the main reasons to choose Fluent Bit.</p><p>From this part of our story, I focus on three main topics.</p><ol><li><em>Sending Application Logs to Stdout as JSON.</em></li></ol><p><em>1.1 JSON Logging with ASP.NET CORE 3.0</em></p><p><em>1.2 JSON Logging with Spring Boot 2.2.1</em></p><p><em>2. Running Fluent Bit On Kubernetes and Forwarding Logs to Elasticsearch</em></p><p><em>3. Showing Logs with Kibana</em></p><h4><strong>1) Sending Application Logs to Stdout as JSON</strong></h4><p>Logs must be in JSON format to index them on Elasticsearch. Since ASP.NET Core and Spring Boot are both popular frameworks, I explain this by creating the REST API project using them.</p><h4><strong>1.1) JSON Logging with ASP.NET CORE 3.0</strong></h4><p>After I tried some libraries to show logs as JSON, I decided to use NLog.</p><p>Firstly Let’s add necessary packages to .csproj file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8219340a6f6dac748b70f542c8627157/href">https://medium.com/media/8219340a6f6dac748b70f542c8627157/href</a></iframe><p>We need to attach the item group to .csproj file for adding nlog.config to bin folder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed266b385b3e207dde3bbfa41edc1c8b/href">https://medium.com/media/ed266b385b3e207dde3bbfa41edc1c8b/href</a></iframe><p>Program.cs must look like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d442926dffe42a59efb026f2044c9aa/href">https://medium.com/media/1d442926dffe42a59efb026f2044c9aa/href</a></iframe><p>We ignore existed loggers with {<strong><em>ConfigureLogging((context, builder) =&gt; { builder.ClearProviders(); })</em></strong>}. If we don’t do this, Loggers from .Net and NLog are both going to log on console.</p><p>Let’s create nlog.config file in the main directory of our project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b412875d1e4c7f71e1bd6b6777714c15/href">https://medium.com/media/b412875d1e4c7f71e1bd6b6777714c15/href</a></iframe><p>Of course, you can add attributes to logs as you wish. That one was just for this example.</p><p>You can benefit from the link below to add different attributes.</p><p><a href="https://nlog-project.org/config/?tab=layout-renderers"><em>https://nlog-project.org/config/?tab=layout-renderers</em></a></p><p>You can reach source code from here.</p><p><a href="https://github.com/ertgamgam/json-logging-asp-net-core"><em>https://github.com/ertgamgam/json-logging-asp-net-core</em></a></p><h4>1.2) JSON Logging with Spring Boot 2.2.1</h4><p>Let’s add this dependency to pom.xml file to show logs in JSON format.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c869180ba5e4caff7509a4f78acdbea7/href">https://medium.com/media/c869180ba5e4caff7509a4f78acdbea7/href</a></iframe><p>We need to add info of HTTP request to MDC by a filter when a request approach to API. Don’t worry. We don’t need to code for this because logback gives us a filter named MDCInsertingServletFilter.</p><p>The only thing we need to do is register for this filter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d41633ecc36a5f3cf916c34f18ca322a/href">https://medium.com/media/d41633ecc36a5f3cf916c34f18ca322a/href</a></iframe><p>We are going to use an interceptor to log HTTP requests. MDCInsertingServletFilter doesn’t add request header to MDC. So We should add headers that we want to log to MDC in the interceptor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3310ff4c8b2bc431883ab5ef72a94ab/href">https://medium.com/media/c3310ff4c8b2bc431883ab5ef72a94ab/href</a></iframe><p>The custom interceptor must be registered.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/921e0ec299b8a7affc6f8decb607e114/href">https://medium.com/media/921e0ec299b8a7affc6f8decb607e114/href</a></iframe><p>Now, let’s add a config file named logback-spring.xml to the resources folder. Spring boot is going to use this file for log configs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/669766df6d637d4fed048acb1a3c7653/href">https://medium.com/media/669766df6d637d4fed048acb1a3c7653/href</a></iframe><p>We reach values that existed in MDC by specifying a key with <em>%X{…}</em></p><p>You can reach source code from here.</p><p><a href="https://github.com/ertgamgam/json-logging-spring-boot"><em>https://github.com/ertgamgam/json-logging-spring-boot</em></a></p><h4><strong>2) Running Fluent Bit On Kubernetes and Forwarding Logs to Elasticsearch</strong></h4><p>Let’s create a new namespace named logging on Kubernetes</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf4f15c4e0836cf8cdfcfd60f8987ee1/href">https://medium.com/media/cf4f15c4e0836cf8cdfcfd60f8987ee1/href</a></iframe><p>By creating ServiceAccount, we are creating an identity for Fluent Bit pods, which is we are going to run.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69d1926bb030ea1493719e8ecabee699/href">https://medium.com/media/69d1926bb030ea1493719e8ecabee699/href</a></iframe><p>We need to create ClusterRole, which is necessary to read logs on node by Fluent Bit pods.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50a7e563ad008c91190c5a74f9ee025b/href">https://medium.com/media/50a7e563ad008c91190c5a74f9ee025b/href</a></iframe><p>Let’s bind ClusterRole to the ServiceAccount.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69fbb163000b1630e38cc98f4c0df857/href">https://medium.com/media/69fbb163000b1630e38cc98f4c0df857/href</a></iframe><p>We need to crate ConfigMap, which belongs to Fluent Bit. Here are some configs that I want to mention it. We are specifying the path of the log file by using <strong><em>path</em></strong> property, which is in the <strong><em>input</em></strong>.</p><p>Kubernetes is mapping log files to <em>/var/log/containers</em>. Container log files named by using information like pod id, container name while they are getting mapped to <em>/var/log/containers</em>.</p><p>The other important point here is specifying the input name as <strong><em>Tail</em></strong>. Tail plugin provides to read all log files by checking regex in path property.</p><p>Name property of output should be <strong>es</strong> to specify output as Elesticsearch.</p><p>Let’s define an index on Elasticsearch by using <strong><em>Lostash_Prefix</em></strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77ef25bed0be6570c6e775b30e329d9d/href">https://medium.com/media/77ef25bed0be6570c6e775b30e329d9d/href</a></iframe><p>Finally, Kubernetes should run Fluent Bit as <em>Deamon Set</em>. With Deamon Set, Kubernetes starts a Fluent Bit pod on every node. Pods of deployment’s logs that we want to reach may run on any node. Therefore Kubernetes run Fluent Bit as Deamon Set.</p><p>Besides this, we need to specify the host of Elasticsearch as an environment variable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b407c403f281a5fdbc78f51ce0ec237/href">https://medium.com/media/6b407c403f281a5fdbc78f51ce0ec237/href</a></iframe><h4><strong>3) Showing Logs with Kibana</strong></h4><p>Firstly We should create an index pattern on Kibana. To do this, let’s click on <em>Management-&gt;Index Pattern-&gt;Create Index pattern</em> and defining index pattern.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OF6uHWSbpuu3WEa8gJlebA.png" /></figure><p>After we choose the index pattern from the Discovery section, we see logs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=411587e54e22" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/forwarding-kubernetes-containers-logs-to-elasticsearch-with-fluent-bit-and-showing-logs-with-411587e54e22">Forwarding Kubernetes Container’s Logs to Elasticsearch with Fluent Bit and Showing Logs with…</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>
        <item>
            <title><![CDATA[ASP.NET Core Hosted Service ile Angular SPA’a Real Time Veri Gönderilmesi]]></title>
            <link>https://ertugrul-gamgam.medium.com/asp-net-core-hosted-service-ile-angular-spaa-real-time-veri-g%C3%B6nderilmesi-d63b8c36a28a?source=rss-7faad67539e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/d63b8c36a28a</guid>
            <dc:creator><![CDATA[Ertuğrul Gamgam]]></dc:creator>
            <pubDate>Sun, 27 Jan 2019 21:35:30 GMT</pubDate>
            <atom:updated>2019-12-16T18:43:00.603Z</atom:updated>
            <content:encoded><![CDATA[<h3>ASP.NET Core 2.2 Hosted Service ile Angular SPA’a Real Time Veri Gönderilmesi</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*NY6w-a6oVIL6FHQ7kQ5lNg.jpeg" /></figure><p>Herkese merhaba. Bugün genel olarak ASP.NET Core’da Hosted Service’in kullanımından bahsedeceğim. Sonrasında Hosted Service üzerinde SignalR service’i çağırarak Angular SPA’a real time veri göndereceğiz.</p><p>Geliştirme sırasında ASP.NET Core 2.2 ve Angular 7 kullanılmıştır.</p><p>ASP.NET Core projesini <a href="https://github.com/ertgamgam/asp.netcore_hostedservice_signalr"><strong><em>buradan</em></strong></a> Angular SPA projesini de <a href="https://github.com/ertgamgam/angular_signalr"><strong><em>buradan</em></strong></a><strong><em> </em></strong>indirebilirsiniz.</p><p><strong>Peki Nedir Bu Hosted Service?</strong></p><p>Bir uygulama geliştirirken background olarak ilerlemesini istediğiniz task’ler olabilir. ASP.NET Core tarafında bu işlemleri Hosted Service aracılığıyla gerçekleştirebiliyoruz.</p><p>ASP.NET Core ile bir API projesi oluşturduktan sonra kodlamaya başlayalım.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ea04f4357263526fe181ccf3284997a/href">https://medium.com/media/2ea04f4357263526fe181ccf3284997a/href</a></iframe><p>Öncelikle “MessagesHub” isimli bir SignalR Hub oluşturuyoruz. Hub SignalR’da gönderilen verinin istemcilere iletilmesini sağlıyor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11bf2b90217af1be67b03e7007941673/href">https://medium.com/media/11bf2b90217af1be67b03e7007941673/href</a></iframe><p>Random olarak mesaj döndürecek olan “MessageProvider” class’ımızı kodluyoruz. (Evet sıkı bir Guns N’ Roses fanıyım 😊 )</p><p>Şimdi sıra geldi HostedService’imize.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afc37991564cea3de4d8ede60af2889b/href">https://medium.com/media/afc37991564cea3de4d8ede60af2889b/href</a></iframe><p>“StartAsync” ve “StopAsync” metotlarımız “IHostedService” interface’i ile implement ettiğimiz metotlar. Bir Hosted Service çalışmaya başladığında constructor’ından sonra “StartAsync” metodu çağrılıyor. Durdurulduğunda ise “StopAsync” metotu çağrılıyor.</p><p>“Dispose” metotu ise “IDisposable” interface’i ile implement ediliyor. Hosted Service’imiz dispose edilirse bu metot çağrılıyor.</p><p>“IServiceProvider” türünde olan “Services”’i constructor injection ile inject ediyoruz. Service provider ile Hosted Service içinde diğer servislerimizi çağırabiliyoruz.</p><p>Timer’ın kullanılma amacı Hosted Service’in belirli aralıklarla istediğimiz işleri gerçekleştirmesini sağlamak. “DoWork” ise timer’ın çağıracağı metot.</p><p>Şimdi “DoWork” içerisinde nelerin gerçekleştiğini inceleyelim. İlk olarak using kalıbı içerisinde “Services”e ait “CreateScope” metodu ile “scoped” isimli, Hosted Service içerisinde başka bir servis çağırmamızı sağlayacak nesnemizi oluşturuyoruz.</p><p>“IHubContext” interface’i ile “MessagesHub”ımızı servis olarak çağırıyoruz.</p><p>Son olarak “MessagesHub” üzerinde “getSendMessage” isimli SignalR metoduna subscribe olmuş tüm client’lara random olarak ürettiğimiz mesajların gönderilmesini sağlıyoruz.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/917fa278fdf3a34e0ea50a18272c9a51/href">https://medium.com/media/917fa278fdf3a34e0ea50a18272c9a51/href</a></iframe><p>Projeyi geliştirme aşamasında Cors ile ilgili bir problem yaşadım. ASP.NET Core 2.0 ile aynı projeyi geliştirdiğimde “AllowAnyOrigin” metodunu kullanarak Hub’a bağlanabilirken, ASP.NET Core 2.2’de aynı projeyi geliştirdiğimde SPA’dan Hub’a bağlanırken browser tarafından Cors hatası alıyordum. Kısa bir araştırmadan sonra “SetIsOriginAllowed” metodunu kullanarak Cors’la ilgili bu hatayı çözdüm.</p><p>Sonrasında HostedService’i ve SignalR’ı servis olarak ekliyoruz.</p><p>“ConfigureService” metodu içerisinde Cors’u ekliyoruz ve Hub’a ulaşacağımız path’i belirtiyoruz.</p><p>Şimdi sıra Angular SPA’ı geliştirmekte</p><p>“ng new HostedServiceClient “ ile bir Angular projesi oluşturuyoruz. Working directory’e gittikten sonra “npm install @aspnet/signalr” ile gerekli SignalR paketlerini projeye ekliyoruz.</p><p>“ng generate service hubconnection” ile projede bir servis oluşturuyoruz.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2a554c5c6b03ef47e584d44eeffe647/href">https://medium.com/media/c2a554c5c6b03ef47e584d44eeffe647/href</a></iframe><p>“Hubconnection” servisi kısaca açıklamak gerekirse Hub’a bağlanmamızı sağlayacak olan “hubConnection” nesnesini tanımlıyoruz ve “createConnection” metodu içinde Hub’ın adresini belirtiyoruz.</p><p>“registerOnServerEvent” metotu ile Hub üzerindeki “getSendMessage” ismi ile belirttiğimiz metoda subscribe oluyoruz ve gelen mesajı “message” isimli “EventEmitter”a atıyoruz.</p><p>“startConnection” metodu ile de Hub’a bağlanıyoruz.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8568514d11a6450ba1e189610048011/href">https://medium.com/media/e8568514d11a6450ba1e189610048011/href</a></iframe><p>Component’in içinde DI ile servisimizi çağırıyoruz ve servisin içinde bulunan “EventEmitter&lt;string&gt;” tipindeki “message” nesnesine, component tarafında “subscribeToMessageEvent” metodu ile “subscribe” oluyoruz.</p><p>Son olarak html kodlarımız.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07d924accd0f2d1c052cad909349068d/href">https://medium.com/media/07d924accd0f2d1c052cad909349068d/href</a></iframe><p>Ve sonuç:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8b9tYUtXLfhijIVVdG9vOg.gif" /></figure><p>Hosted Service üzerinden client’a gönderilen mesajlar sayfa üzerinde real time güncelleniyor.</p><p>Bir makalenin daha sonuna geldik. Kodla kalın.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d63b8c36a28a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ASP.NET Core ile MongoDB Üzerinde Repository Pattern Kullanarak CRUD İşlemlerinin Yapılması]]></title>
            <link>https://ertugrul-gamgam.medium.com/asp-net-core-ile-mongodb-%C3%BCzerinde-repository-pattern-kullanarak-crud-i%CC%87%C5%9Flemlerinin-yap%C4%B1lmas%C4%B1-c5d301ea8d3e?source=rss-7faad67539e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5d301ea8d3e</guid>
            <category><![CDATA[repository-pattern]]></category>
            <category><![CDATA[crud]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[aspnetcore]]></category>
            <dc:creator><![CDATA[Ertuğrul Gamgam]]></dc:creator>
            <pubDate>Sun, 13 Jan 2019 10:54:27 GMT</pubDate>
            <atom:updated>2019-12-16T18:52:42.193Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>ASP.NET Core 2.1 ile MongoDB Üzerinde Repository Pattern Kullanarak CRUD İşlemlerinin Yapılması</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*rM5XN25goO7JlPFHrfPZzg.png" /></figure><p>Herkese merhaba. Uzun zamandır aklımda medium.com’a makale ekleme fikri vardı. Fakat bir yandan okul bir yandan iş bir türlü zaman ayıramadım. Hazır okul tatil olmuşken fırsat bu fırsat deyip ilk makalemle sizlerleyim.</p><h3>MongoDB</h3><p>MongoDB open source NoSQL çözümüdür. Peki neden RDBMS(Relational Database Management System) ler varken NoSQL kullanmayı tercih ederiz? Sürekli artan veri boyutları, sistemimizin okuma ve yazma işlemlerinde performans kaybı yaşamasına sebep olmaktadır. Bir de yüksek trafikli bir sistemimiz varsa performans kayıplarının yaşanması kaçınılmaz oluyor. NoSQL sistemler bu performans kaybını önlemede en büyük yardımcılarımızdan biri oluyorlar.</p><p>RDBMS kavramlarından table MongoDB’de collectionlara, row ise document kavramına karşılık gelmektedir.</p><p>Projeyi <a href="https://github.com/ertgamgam/asp.netcore_mongodb"><strong><em>buradan</em></strong></a> indirebilirsiniz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*WzJHZ8S2U_h9RVvEcI1Yaw.jpeg" /></figure><p>Öncelikle Visual Studio üzerinden bir ASP.Net Core API projesi oluşturalım. Sonrasında Mongo driver’ı projemize dahil edelim.</p><p><strong><em>Install-Package MongoDB.Driver -Version 2.7.2</em></strong></p><p>Artık model class’ımızı yazarak kodlamaya başlayabilirz. Öncelike MongoBaseModel adlı abstract bir class oluşturuyoruz.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad97081d4560eddadbef147d614dc427/href">https://medium.com/media/ad97081d4560eddadbef147d614dc427/href</a></iframe><p>ObjectId MongoDB’de document’lerin primary key’idir. Bir document oluşturulduğunda MongoDB tarafından objectid atanır. Yani her document bir objectid’e sahiptir. .NET Core tarafında da bir class’ın MongoDB model class’ı olabilmesi için “ObjectId” türünden “Id” isimli property’e sahip olması gerekmektedir.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88a81713ebbaff09d5397e8c7be8b092/href">https://medium.com/media/88a81713ebbaff09d5397e8c7be8b092/href</a></iframe><p>Sonrasında RockSongs isimli model class’ımızı oluşturuyoruz. Bu class MongoBaseModel class’ını inherit ediyor. BsonElement MongoDB tarafında, collection’ın property’sini isimlendirmek amacıyla kullanılan bir attribute.</p><p>Şimdi gelelim işin en eğlenceli yanı olan Repository bölümüne.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db4bd49d1fbfc68b563e8618c6eff413/href">https://medium.com/media/db4bd49d1fbfc68b563e8618c6eff413/href</a></iframe><p><em>Her model’imiz için tekrardan repository yazarak kod tekrarı yapmak yerine abstract bir base repository oluşturuyoruz ve TModel generic türünü tanımlıyoruz.</em></p><p><em>Constructor’da ise MongoDB’ye bağlanma işlemlerini gerçekleştiriyoruz ve istediğimiz collection’ın getirilmesini sağlıyoruz.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4987ff175d4569bd31576d2851bd8025/href">https://medium.com/media/4987ff175d4569bd31576d2851bd8025/href</a></iframe><p>RockSongsRepository’miz, RockSongs modeli ile CRUD işlemlerini sağlayacak service’imiz. Artık burada repository pattern kullanımının faydalarını görmeye başlıyoruz. RockSongsRepository, BaseMongoRepository’i inherit ediyor ve TModel olarak da RockSongs belirtiliyor. Bunlar dışında, başka bir kod yazmadan RockSongsRepository’nin CRUD işlemlerini yerine getirmesini sağlamış oluyoruz.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82750d087e1f2ccd68782068ff1bc1f9/href">https://medium.com/media/82750d087e1f2ccd68782068ff1bc1f9/href</a></iframe><p>appsettin.json’a connection string’imi eklemeyi unutmuyoruz tabi ki.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6dde68c86c00e8b2a20d60308ab6363/href">https://medium.com/media/c6dde68c86c00e8b2a20d60308ab6363/href</a></iframe><p>Sonrasında MongoRockSongsRepository’i transient service olarak ekliyoruz. Burada constructor içinde ki Songs isimli parametre database ismine, RockSongs ise collection ismine karşılık geliyor. Önceden MongoDB üzerinde bu isimlerde database ve colletion oluşturmanıza gerek yok. İlk documenti eklemeyi denediğinizde mongo driver sizin için bu yapıları oluşturuyor.</p><p>Şimdi son olarak controller class’ımızı oluşturmaya geldik. Öncelikle bir base controller oluşturuyoruz ardından bu base controller’ı inherit eden bir RockSongsController oluşturuyoruz.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0488acbe6293d148a406c5bef3cbf2aa/href">https://medium.com/media/0488acbe6293d148a406c5bef3cbf2aa/href</a></iframe><p>BaseMongoController, BaseMongoRepository’i constructor injection ile inject ediyor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b238d7f6e0ca7d404ae6d3bedfa79501/href">https://medium.com/media/b238d7f6e0ca7d404ae6d3bedfa79501/href</a></iframe><p>Şimdi postman ile projemizi test edelim.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l8Z-N_PEcISBSQrXqtHlAQ.jpeg" /></figure><p>Önce service’e iki defa aynı veriler ile post request gönderiyorum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*teDcMlCB1qsaeUsmUz-rwg.jpeg" /></figure><p>Sonrasında get reqeust gönderiyorum ve service’mizin başarılı bir şekilde çalıştığını görüyoruz.</p><p>İlk makalemizin sonuna geldik. Yeni bir makalede görüşmek üzere hoşçakalın.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5d301ea8d3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>