<?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 Ercan Gerçek on Medium]]></title>
        <description><![CDATA[Stories by Ercan Gerçek on Medium]]></description>
        <link>https://medium.com/@ercangercek?source=rss-d9f04230452------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*R0xzgTYg__mxH6RPd-fuRQ.jpeg</url>
            <title>Stories by Ercan Gerçek on Medium</title>
            <link>https://medium.com/@ercangercek?source=rss-d9f04230452------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 21:47:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ercangercek/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[Build Fast, Deploy Faster: How to Lower Your Cycle Time]]></title>
            <link>https://ercangercek.medium.com/build-fast-deploy-faster-how-to-lower-your-cycle-time-da6520e98121?source=rss-d9f04230452------2</link>
            <guid isPermaLink="false">https://medium.com/p/da6520e98121</guid>
            <category><![CDATA[cycle-time]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[agile-development]]></category>
            <category><![CDATA[deployment]]></category>
            <dc:creator><![CDATA[Ercan Gerçek]]></dc:creator>
            <pubDate>Mon, 05 May 2025 20:48:13 GMT</pubDate>
            <atom:updated>2025-05-05T20:48:13.414Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Mv-b5euV_FMe2pfj" /><figcaption>Photo by <a href="https://unsplash.com/@marvinradke?utm_source=medium&amp;utm_medium=referral">Marvin Radke</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Cycle time is the total duration from the start of a development task to when the feature becomes available to users in production. It begins when the task starts and ends when the feature is deployed. It is a strong indicator of the health of a software development process. Ideally, this metric should be as low as possible, without sacrificing quality, maintainability, or scalability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lXIyOvi_Oxr8--a7-PVRJg.png" /><figcaption>Cycle Time vs Lead Time</figcaption></figure><p>To reduce cycle time, a team must be able to respond quickly to changes while maintaining a resilient system. Software quality, scalability and availability must not be compromised.</p><p>We can explore this subject through five key areas:</p><ul><li>Maintainability</li><li>Testability</li><li>Ease of Deployment</li><li>Scalability</li><li>Availability</li></ul><h3>Maintainability</h3><p>Maintainability refers to how easily changes can be made in a software project. This includes adding, removing, or updating features, applying security patches, or upgrading frameworks.</p><p>Key characteristics of maintainable software include:</p><ul><li>Easy to locate where changes or new features should be implemented</li><li>Well-separated components with meaningful coupling between modules</li><li>Clear separation of classes/functions to avoid complexity</li><li>Reasonable size and complexity of components/classes/functions</li><li>Fewer dependencies between components</li></ul><p>A good indicator of maintainability is the number of bugs introduced after a task is implemented. For example, if a new feature or bug fix breaks another part of the system, it indicates poor maintainability.</p><h3>Testability</h3><p>Testability reflects the confidence you have in the system after making a change. It can be broken down into three main factors:</p><ul><li><strong>Ease of Testing:</strong> Unit tests and automated end-to-end (E2E) tests should be used to verify that the application still works after changes. The easier and more automated this is, the better.</li><li><strong>Test Coverage:</strong> The broader the coverage, the higher the confidence after a successful test run. If only the happy paths are tested, additional manual testing is needed, consuming more time.</li><li><strong>Impact Radius of a Change:</strong> If a small change requires testing the entire application, it could be a sign of tight coupling. A well-structured system should allow localized changes with minimal ripple effects.</li></ul><h3>Deployability</h3><p>Deployability is not only about how easily you can deploy but also how frequently and safely you can do so. Deploying every two weeks increases risk and delays the release of completed features and bug fixes.</p><p>Systems with modular architecture and separately deployable units:</p><ul><li>Require less deployment coordination and ceremony</li><li>Carry lower deployment risks</li><li>Can be deployed more frequently than monoliths</li></ul><p><strong>Ideal Deployability Example:</strong> Deploying multiple times a day in small, independent iterations with no ceremony</p><p><strong>Low Deployability Example:</strong> Deploying every two weeks with complex processes and ordering constraints</p><h3>Scalability</h3><p>Scalability is the ability of a system to remain responsive as user load gradually increases. Elasticity, on the other hand, refers to handling sudden and significant spikes in load (e.g., after a TV advertisement).</p><ul><li><strong>Elasticity</strong> is influenced by the <strong>granularity</strong> of the deployment unit — how small and independently scalable the components are.</li><li><strong>Scalability</strong> depends on <strong>modularity</strong> — the separation of concerns into independently deployable units.</li></ul><p><strong>Monoliths: </strong>Slow to start, hard to scale, low in elasticity and scalability</p><p><strong>Service-based architectures: </strong>Easier to scale due to separable units, may still suffer from long startup times</p><p><strong>Microservices: </strong>High elasticity and scalability, fast to start, independently deployable, should be loosely coupled and avoid service-to-service dependencies</p><h3>Availability / Fault Tolerance</h3><p>Breaking an application into separately deployable units increases fault tolerance. In a catastrophic failure, only part of the system is affected rather than the whole.</p><p>Potential causes of partial failures include:</p><ul><li>Software bugs</li><li>Network issues</li><li>Out-of-memory conditions</li><li>Infrastructure Outages / Cluster problems</li></ul><p>A modular architecture makes your system more resilient and helps reduce downtime.</p><p>These five areas are essential for building agile and responsive software systems. Evaluating your project on maintainability, testability, deployability, scalability, and availability can help identify growth opportunities and reduce cycle time.</p><p>While architectural improvements reduce time-to-market, the Four Key Metrics are a strong indicator of agility.</p><ul><li><strong>Deployment Frequency</strong>: How often you release to production.</li><li><strong>Lead Time for Changes</strong>: Time from commit to production.</li><li><strong>Change Failure Rate</strong>: Percentage of deployments causing production issues.</li><li><strong>Time to Restore Service</strong>: How quickly you recover from failures.</li></ul><p>Take care and happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da6520e98121" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Race conditions in Golang]]></title>
            <link>https://medium.com/trendyol-tech/race-conditions-in-golang-511314c0b85?source=rss-d9f04230452------2</link>
            <guid isPermaLink="false">https://medium.com/p/511314c0b85</guid>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Ercan Gerçek]]></dc:creator>
            <pubDate>Thu, 17 Jun 2021 19:52:40 GMT</pubDate>
            <atom:updated>2024-08-16T08:34:36.465Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kkP0sHm9LkbZsiJh" /><figcaption>I like Formula1, so here is a photo of a race car. Photo by <a href="https://unsplash.com/@cuadpaul?utm_source=medium&amp;utm_medium=referral">Paul Cuad</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Writing multi-threaded applications is a non-trivial job and requires planning before implementation. If you are using a single-threaded language such as JavaScript, understanding the basics is quite essential. However, if you are familiar with low-level languages like C or C++, the concepts are similar. In this blog post, I want to explain how race condition occurs and how to synchronize data access using Golang.</p><blockquote>Warning: If you are new to Go and don’t know about channels, consider looking into that topic. In my personal opinion, it is easier to communicate over channels, instead of sharing variables. If you don’t share variables, then there won’t be any race conditions.</blockquote><h3><strong>What is a race condition?</strong></h3><p>A race condition occurs when multiple threads try to access and modify the same data (memory address). E.g., if one thread tries to increase an integer and another thread tries to read it, this will cause a race condition. On the other hand, if the variable is read-only, there won&#39;t be a race condition. In golang, threads are created implicitly when Goroutines are used.</p><p>Let’s try to create a race condition. The easiest way to do it is by using multiple goroutines, and at least one of the goroutines must be writing to a shared variable.</p><p>The following code demonstrates a simple way to create a race condition.</p><ul><li>A goroutine reads the variable named “sharedInt”</li><li>Another goroutine writes to the same variable by increasing its value.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f54b1c192cf7a4e2b0cf0a164a8214de/href">https://medium.com/media/f54b1c192cf7a4e2b0cf0a164a8214de/href</a></iframe><p>If you run this code, this will not result in a crash, but sometimes the reader goroutine will access an outdated copy of “sharedInt”. If you run the code with the built-in race condition checker, the go compiler will complain about the problem.</p><p><strong>go run -race .</strong></p><blockquote>A small note about the Golang race condition checker: if your code occasionally accesses shared variables, it might not be able to detect the race condition. To detect it, the code should run in heavy load, and race conditions must be occurring.</blockquote><p>You can see the output of the race condition checker. It complains about unsynchronized data access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*__U__l2ocAkpXhsQzQXK6Q.png" /></figure><p>How can we solve this problem? If the shared data is a single variable, we can use counters provided in the <a href="https://golang.org/pkg/sync/atomic/">sync/atomic pack</a>. In the following example, instead of accessing the shared variable directly, we can use the <strong>atomic.LoadInt64()/atomic.AddInt64()</strong> pair to access it. The race condition checker will not complain about the unsynchronized data access anymore.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/983f544c125635aa3712d5598bb533a7/href">https://medium.com/media/983f544c125635aa3712d5598bb533a7/href</a></iframe><p>This solves our problem when using primitive variables, but we need to access multiple variables and work with complex data structures in many cases. In these cases, it makes sense to control the access by using mutexes.</p><p>The following example demonstrates unsynchronized access to a map. When using complex data structures, race conditions could result in a crash. Therefore, if we run this example without race check enabled, the go runtime will complain about the concurrent access, and the process will exit.</p><p><strong>fatal error: concurrent map read and map write</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe11dd4611b8ed680de322a6e3bbfb9e/href">https://medium.com/media/fe11dd4611b8ed680de322a6e3bbfb9e/href</a></iframe><p>It is possible to fix this problem by controlling access to the critical section. In this example, the critical section is where we read and write to the “sharedMap”. In the example below, we call <strong>mutex.Lock()</strong> and <strong>mutex.Unlock()</strong> pair to control the access.</p><h4>How does mutex work?</h4><ul><li>Mutex is created in an unlocked state.</li><li>When the first call to mutex.Lock() is made, mutex state changes to Locked.</li><li>Any other calls to mutex.Lock() will block the goroutine until mutex.Unlock() is called</li><li>So, only one thread can access the critical section.</li></ul><p>For example, we can control access to the critical section by using a mutex. I added a context to cancel the goroutines after working for 2 seconds. You can ignore the code related to context if you are not familiar with it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f599de373a7d2459c66c4fbc337b625b/href">https://medium.com/media/f599de373a7d2459c66c4fbc337b625b/href</a></iframe><p>If we run the example code, go runtime will not complain about concurrent map read and map write anymore because only one goroutine can access the critical section at a time.</p><p>In the example, I used 15 reader goroutines and a single writer goroutine. The writer updates the “sharedMap” every 100 milliseconds. It could be better to use RWMutex (reader/writer mutual exclusion lock) in cases like this. It is similar to a mutex, but it also has another locking mechanism to let multiple readers access the critical section when it is safe. This could perform better when writes are rare, and reads are more common.</p><h4>How does RWMutex works?</h4><ul><li>In simpler terms, multiple readers can access the critical section if there are no writers. If a writer tries to access the critical section, all reads are blocked. This is more efficient when the writes are rare, and the reads are common.</li><li>rwMutex.Lock() and rwMutex.Unlock() works similarly to the mutex lock-unlock mechanism.</li><li>rwMutex.RLock() does not block any readers if the mutex is in an unlocked state. This lets multiple readers access the critical section at the same time.</li><li>When rwMutex.Lock() is called; the caller is blocked until all readers call rwMutex.RUnlock(). At this point, any calls to RLock() start to block until rwMutex.Unlock() is called. This prevents any starvation from occurring.</li><li>When rwMutex.Unlock() is called; all the callers of RLock() are unblocked and can access the critical section.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c42991c353409b433965c37d2196d7e/href">https://medium.com/media/2c42991c353409b433965c37d2196d7e/href</a></iframe><h4>Mutex vs RWMutex Performance</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R0gasrKSZ9Ai6asn_GesvA.png" /></figure><p>I ran the examples five times and compared the averages. As a result, RWMutex performed 14.35% more read operations. But please keep in mind that this example is highly biased as there are 15 reader goroutines and a single writer goroutine.</p><h4>Conclusion</h4><p>In this blog post, I tried to go over the basics of unsynchronized data access, which results in race conditions. If you are not familiar with multi-threaded programming, it is easy to overlook this and run into problems.</p><p>In my personal experience, I would prefer making every goroutine/thread use its own variables in an isolated context and propagating the changes to an aggregator by using channels. Usually, it is easier to design single-threaded components that communicate over channels or queues. However, this approach is not suitable in every case, and mutexes can come in handy.</p><p>Thanks for reading. If you have any feedback or find a mistake, please let me know.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=511314c0b85" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/race-conditions-in-golang-511314c0b85">Race conditions in Golang</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[Experiment with 3D Boids and JavaScript]]></title>
            <link>https://ercangercek.medium.com/experiment-with-3d-boids-and-javascript-fe8fa51707b8?source=rss-d9f04230452------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe8fa51707b8</guid>
            <category><![CDATA[threejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[webgl]]></category>
            <category><![CDATA[webworker]]></category>
            <dc:creator><![CDATA[Ercan Gerçek]]></dc:creator>
            <pubDate>Fri, 13 Nov 2020 18:44:31 GMT</pubDate>
            <atom:updated>2020-11-13T18:44:31.613Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QPg8QNhfDXU359fC.jpg" /></figure><h3>Introduction</h3><p>One of my favourite algorithms is <a href="https://en.wikipedia.org/wiki/Boids">the boids</a>. You can create a flock movement with it. It is easy to understand, and the results are visually convincing. I used it first in one of my games to mimic fleet behaviour. In that game, users were able to move their fighter aircraft with the mouse input. Using the boids algorithm make the animation smooth and believable. That game was in 2D, and I implemented it in C++, so this time, I wanted to implement it in 3D with JavaScript. Calculating many small entities is computationally heavy. On the positive side, discrete operations can be distributed to threads. In this experiment, I implemented my version of the boids algorithm and tried to optimize it using grids (3d bucket lists) and WebWorkers. You can find the source code in <a href="https://github.com/ercang/boids-js">The GitHub Repo</a>.</p><p><strong>You can check out the demo by </strong><a href="https://ercang.github.io/boids-js/2-boids-grids/"><strong>clicking here</strong></a><strong>.</strong></p><h3>The Implementation of The Boids</h3><p>The boids algorithm consists of three basic rules, alignment, cohesion and separation. Also, I added another one for entities to avoid obstacles and boundaries of the world. All of these rules work for a single entity if there is another entity within the awareness radius.</p><ul><li><strong>Alignment:</strong> Entity’s direction is aligned with the average direction in the awareness radius.</li><li><strong>Cohesion:</strong> This rule is about how much entities are inclined to stick together. Entities try to move to the center of the flock within the awareness radius.</li><li><strong>Separation:</strong> If entities are too close, they steer away from each other. Again this rule is applied in the awareness radius.</li><li><strong>Obstacle Avoidance:</strong> Obstacles are different type of entities which are not a part of the flock. These entities represent an obstacle. If an entity gets too close to an obstacle entity, it steers away from it. This rule is also applied for the world boundaries.</li></ul><h3>Boids Running in the Browser Thread</h3><p>After completing the basics of boids, I implemented a simple renderer with ThreeJS to visualize the entities. The spheres represent the obstacles, and the boxes represent the entities in the flock. In the first test case, the iteration must be completed before rendering occurs. The algorithm’s complexity is O(n²)</p><p>The blue line represents total milliseconds to compute a single iteration. The red line represents frames per second. The horizontal axis represents the total entity count. I ran the tests starting from 400 entities and increased the entity count to 3000 at the end. As can be seen from the chart, FPS drops dramatically as the number of entities increase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wBIylPcNuRsqKYuG3PH3LQ.png" /></figure><p>It is practically unusable after 800 boids as it drops to 30 frames per second. Also, it is running in the browser thread, so it prevents UI to be updated. You can run this example from the link given below.</p><p><a href="https://ercang.github.io/boids-js/1-boids-simple/"><strong>Run Example 1</strong></a></p><h3>Implementing Spatial Partitioning</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Dc62ks2ZJQfPPVPJ.jpg" /></figure><p>Boids algorithm uses nearby entities to calculate an entity’s position and velocity. E.g., if a nearby obstacle is found, an avoidance vector is calculated, or if an entity has a nearby neighbour, it tries to align with it. To speed up finding nearby entities, I used a grid system. Alternatively, an octree could be implemented as it will be more memory efficient but implementing a grid is simpler; that’s why I selected the grid system for this case.</p><p>Basically grid system makes a three-dimensional array for the world. It is easy to find an entity’s grid index from its position. If an entity needs to be moved, first the current grid is found, and then the entity is removed from that grid, and afterwards, it is added to the new grid. It is computationally very cheap to find the entities in a grid as the list is already prepared. You can find more information about spatial partitioning <a href="http://gameprogrammingpatterns.com/spatial-partition.html">here</a>.</p><p>Implementing a grid system increased performance significantly. You can run this example from the link given below. In this example, the world is quite crowded, so if it were more sparse, the time required to compute a single iteration would increase more linearly. For the best performance, entities should be distributed equally to the cells. If all entities pile up in the same cell, then there will not be any performance improvement.</p><p><a href="https://ercang.github.io/boids-js/2-boids-grids/"><strong>Run Example 2 — Grid Support</strong></a></p><h3>Distributing the work using WebWorkers</h3><p>There is more room to make the implementation better. We can distribute the workload among different WebWorkers. The upside of making the computation on the WebWorker is separating the work from the UI thread. It will keep the application running at 60 FPS even though the calculation takes more than 16,6 (1000/60) milliseconds. The downside of this approach is having to copy all the world data to WebWorkers and copying it back when they complete the computation on each WebWorker.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*-TCUG2YDW3dmxDtOH5Tbow.png" /></figure><p>In the WebWorker case, there is a small inconsistency with computing all the data sequentially in a single thread. In the example given above, there are 500 entities. The iteration is done separately for every 250 entities, and they do not affect each other during the iteration. But this does not create a problem with our simulation. It is a minor difference, and the results can not be observed visually. Also, to keep the visualization smooth, the position of every entity is interpolated. If the WebWorker can not complete the job for the next render loop, the renderer still updates the entities in the browser thread.</p><p>Using WebWorkers makes the simulation smoother. You can run this example from the link given below. In this example case, using four workers made the most improvement. Using multiple workers cause entity data to be copied numerous times. I think after four WebWorkers, copying the data takes most of the time, and I didn’t see any performance improvement. It might be better to use SharedArrayBuffer to prevent copying data. I only implemented “object serialize” methods for the classes, so with proper implementation, SharedArrayBuffer can be used.</p><p><a href="https://ercang.github.io/boids-js/3-boids-webworkers/"><strong>Run Example 3 — WebWorkers [Chrome Only]</strong></a></p><p><strong>Why this example only works with Chrome?</strong><br>The WebWorker example only works with Chrome because Safari and Firefox do not support import statements in WebWorkers. It is usually not a problem, because using a script packer (e.g. Webpack) should merge all the source files into a single file. To keep the examples simple, I didn’t use a script packer.</p><h3>Results</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XWazag8AfR_DXcRN.jpg" /></figure><p>The results of the tests are combined into a single chart given above. Blue, red and orange lines represent the example 1,2 and 3 in that order. So it is easier to see the difference between these examples in terms of performance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe8fa51707b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>