<?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 Djohanprabowo on Medium]]></title>
        <description><![CDATA[Stories by Djohanprabowo on Medium]]></description>
        <link>https://medium.com/@djohanprabowo97?source=rss-7b7ddce04777------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0aYmcLVAsG0pPL-N5Nk8MA.jpeg</url>
            <title>Stories by Djohanprabowo on Medium</title>
            <link>https://medium.com/@djohanprabowo97?source=rss-7b7ddce04777------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 22:30:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@djohanprabowo97/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[Store and Reinit Key Value Config (Case : Microservice Architecture Using Go Lang)]]></title>
            <link>https://djohanprabowo97.medium.com/store-and-reinit-key-value-config-case-microservice-architecture-using-go-lang-171f737d05e5?source=rss-7b7ddce04777------2</link>
            <guid isPermaLink="false">https://medium.com/p/171f737d05e5</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[key-value-store]]></category>
            <category><![CDATA[publish-subscribe-pattern]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Djohanprabowo]]></dc:creator>
            <pubDate>Sun, 06 Dec 2020 23:01:57 GMT</pubDate>
            <atom:updated>2020-12-10T13:22:57.252Z</atom:updated>
            <content:encoded><![CDATA[<h3>Store and Reinit Key Value Config (Case : Microservice Architecture Using Go Lang)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KdGOFV54ylYAmKuqd8QCEA.png" /></figure><p>Key Value is an array to store data, each key only store single value. The value such as integer, string, boolean, or any type data. The key is unique identifier. Example of representation Key Value with this image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*bqLUr1aeQTFRugK2ngsM1A.png" /></figure><p>Key Value can be used for feature flag and configs service. Consul KV is one technology implement Key Value. Consul KV allows users to store indexed objects, though its main uses are storing configuration parameters and metadata (link related : <a href="https://www.consul.io/docs/dynamic-app-config/kv">Consul KV</a>)</p><p>In this article, I will share how to make the KV mechanism to store config with Postgre database, Redis, and the Go Lang programming language. Github link for this project library : <a href="https://github.com/DjohanP/dbkvconfig">https://github.com/DjohanP/dbkvconfig</a></p><h3>Problem</h3><p>In my workplace, we have many config for services like feature flags. To change config, we must deployed first. This takes a long time (around 30 minutes) because we need deploy first. It is not effective if we have to change config frequently.</p><p>To solve the problem, I would create simple storage to store config and to get config from database. It can be solution if we had only one server. So, we must make new solution for services have more than one server.</p><h3>Concept &amp; Architecture Service</h3><p>I was reminded of the concept publish subscribe messaging like NSQ technology. The concept we only publish data and another subscribe data. I think it can solve the problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fJIsJhbM1b6zBpuxRO36fg.png" /></figure><p>So I think how we can make publish subscribe concept. We only publish message and server know to reinit. Depiction like the developer wants to tell the server to reinit and the server automatically reinit</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vy4Y_G6lyNUrJPTiK3RvUQ.png" /></figure><p>We cannot use NSQ because we must have many channel and very complex if the server not permanent. Then I think, I can use redis to store and implement pubsub messaging. We can using key redis like topic in pubsub messaging. And value of redis like message in pubsub messaging. The logic if we store in redis, it indicates there has been a change and requires a reinit config. This is flowchart for logic this project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*kdvjThVOUfda-ZgrB4F3Eg.png" /></figure><p>This is image for approach architecture for this project. All server must connect to redis for subscribe message and to reinit config. And server must connect to Database to get current config.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KdGOFV54ylYAmKuqd8QCEA.png" /></figure><p>In the beginning of the project. I use command HMSET and HGETALL redis to make simple publish subscribe messaging. After that, I found redis has publish subscribe mechanism. It&#39;s very helpful for this project (Docs Link : <a href="https://redis.io/topics/pubsub">https://redis.io/topics/pubsub</a>).</p><h3>Explanation Project Solution with Code</h3><ul><li>Core Library DBKVConfig</li></ul><p>Core of library is listener redis and reinit config after that. There are two method for listener redis with simple command (HMSET and HGETALL) or using publish subscribe messaging redis. Before reinit config, we must validating the new value with current type value.</p><ul><li>Init Library DBKVConfig</li></ul><p>The first we must init library DBKVConfig. The parameter for init function is master, slave DB Connection, redis connection, array KeyValueInit, and options of user preferences. This is example for init library.</p><p>Note : we must set default value for KeyValueInit struct, so we can validating when updating data and if we use struct, we must set with pointer. Options UseRedisPubSub to decide want using redis pubsub or not.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebffd8532c077344e29977b2336b8220/href">https://medium.com/media/ebffd8532c077344e29977b2336b8220/href</a></iframe><ul><li>Get Config from Key</li></ul><p>To get current value from key. We can using function GetConfig. In this function return error If config not saved on struct. After we got config we must construct with type because it&#39;s using interface{}.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89286d22fae0d2dc3b3bdd6fd6d0c05b/href">https://medium.com/media/89286d22fae0d2dc3b3bdd6fd6d0c05b/href</a></iframe><ul><li>Update Config from Key</li></ul><p>To update current config we can using function UpdateConfig. In this function step is validating value with current type, after that update DB, and publish message redis.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d66a070de71a25c4cf7ae9b7abd19e7/href">https://medium.com/media/7d66a070de71a25c4cf7ae9b7abd19e7/href</a></iframe><ul><li>Insert New Config</li></ul><p>When we have new config, we must inserting config first before deploy new config. We can use function InsertConfig. It&#39;s only insert to DB.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0561d9a4c734b2f026897f46b54bc968/href">https://medium.com/media/0561d9a4c734b2f026897f46b54bc968/href</a></iframe><ul><li>Full example handler can see in this link (<a href="https://github.com/DjohanP/dbkvconfig/tree/main/example/http">https://github.com/DjohanP/dbkvconfig/tree/main/example/http</a>)</li></ul><h3>Conclusion</h3><p>If we have one service with more than one server this can be helpful as we only update using one endpoint and all servers with quick reconfiguration. It is the result with different port.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hDSVl0eheeDfyao9zrvHA.png" /></figure><p>We have to be creative and take advantage of existing technology to solve the problem. We must be able to <em>Make It Happen </em>for solution. #MulaiAjaDulu</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=171f737d05e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Simple Debugging in Golang with Real Case on Workplace]]></title>
            <link>https://djohanprabowo97.medium.com/how-to-simple-debugging-in-golang-with-real-case-on-workplace-947a61728036?source=rss-7b7ddce04777------2</link>
            <guid isPermaLink="false">https://medium.com/p/947a61728036</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[debug]]></category>
            <category><![CDATA[efficient]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[Djohanprabowo]]></dc:creator>
            <pubDate>Thu, 12 Nov 2020 15:33:44 GMT</pubDate>
            <atom:updated>2020-11-16T03:11:22.116Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Simple Debugging in Golang</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XwnCe6sFIa3_gK8qa80-wA.png" /><figcaption>Image retrieved from <a href="https://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Go_Logo_Blue.svg/1200px-Go_Logo_Blue.svg.png">wikimedia.org</a></figcaption></figure><p>Golang is one of my favorite language programming. It is very simple and understandable code. Golang is one of the fastest compiling languages. But when we code with carelessly, it can make problem to future. In this article, I will share about one of experiences with Golang in real job :)</p><h3>Introduction Problem</h3><p>In my workplace we have many services with Golang for backend. One of services that is handled by my team had one problem. When reloading service, CPU is always high and time for reloading is long about three minutes. It is very weird, because the preparation to init it is very simple. The preparation is only connect with redis, database, and init class. This problem hinders work. Because if we want changes some config rapidly, it can harm the server. So we must erase the obstacle. It’s very challenging for me and my team.</p><h3>Let’s Beat Obstacle</h3><ul><li>The first we must knowing about the issues. We must be able to decide about tools or way to knowing the problem. So in this case, we know one of the problems is long execution time. So, we decide using time.since(). Because it can easy to trace which execution is taking very long. We give code from main function first. After we run the application we got info about execution every process. We can easily take investigate child process with time.since until we know the main problem. So it is very simple to debug. Example pseudocode</li></ul><pre>start := time.Now()<br>InitModule1()<br>log.Println(&quot;Execution InitModule1 :&quot;,time.Since(start).Seconds())</pre><pre>start = time.Now()<br>InitModule2()<br>log.Println(&quot;Execution InitModule2 :&quot;,time.Since(start).Seconds())</pre><pre>start = time.Now()<br>InitModule3()<br>log.Println(&quot;Execution InitModule3 :&quot;,time.Since(start).Seconds())</pre><pre>start = time.Now()<br>InitModule4()<br>log.Println(&quot;Execution InitModule4 :&quot;,time.Since(start).Seconds())</pre><ul><li>Finaly I got the problem, which process is taking a very long time. It’s very simple code and I never expect this is the root cause of the problem. The code is very tidy but it’s very not efficient. And I didn’t expect that config containts more than 20 configs type with every types containts more than 2 mode and the function validation had many iteration. Example pseudocode</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba566f884c660e33ff32c945daffeb46/href">https://medium.com/media/ba566f884c660e33ff32c945daffeb46/href</a></iframe><ul><li>After we know the problem I try improvement with using type data map. First we looping config.Available to construct map data. After that can decrease our duplicate looping. Example pseudocode</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15a6df0d54c60c3c416806da4009e8be/href">https://medium.com/media/15a6df0d54c60c3c416806da4009e8be/href</a></iframe><h3>Result</h3><p>After doing improvement, we got achieve execution for reloading service only 2s and the cpu only spike to arround 1–2% only. This is very satisfying. because this really makes maintenance service well without having to wait long when we want to change config rapidly :)</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FEOpZ7XsVfTN2E%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fminions-EOpZ7XsVfTN2E&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2FEOpZ7XsVfTN2E%2Fgiphy-downsized-large.gif%3Fcid%3D790b76117e7dae0603d7a670ee490ea5baf747929df3a4da%26rid%3Dgiphy-downsized-large.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="219" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed2d376bf3fcc4fb4ab6c164c1fd1b5c/href">https://medium.com/media/ed2d376bf3fcc4fb4ab6c164c1fd1b5c/href</a></iframe><h3>Conclusion</h3><p>We must be carefull when code using iteration case. Because when our code is not efficient it can make problem in features. Some of the tips for this case are using time.since very helping to decide which process is taking too long and using map data can improvement our iteration.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=947a61728036" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>