<?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 Jaeeun Cho on Medium]]></title>
        <description><![CDATA[Stories by Jaeeun Cho on Medium]]></description>
        <link>https://medium.com/@jaeeunchodev?source=rss-c17d6cda7c7e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Q-9-diHY2mtnLnvPw8CXuQ.jpeg</url>
            <title>Stories by Jaeeun Cho on Medium</title>
            <link>https://medium.com/@jaeeunchodev?source=rss-c17d6cda7c7e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 14:26:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jaeeunchodev/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[Weird Go Enum Leads to Lesson: Different Project Structure]]></title>
            <link>https://medium.com/@jaeeunchodev/weird-go-enum-leads-to-lesson-different-project-structure-3460951bbbf2?source=rss-c17d6cda7c7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/3460951bbbf2</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[enumeration]]></category>
            <category><![CDATA[project-structure]]></category>
            <category><![CDATA[style-guides]]></category>
            <dc:creator><![CDATA[Jaeeun Cho]]></dc:creator>
            <pubDate>Mon, 10 Oct 2022 06:16:57 GMT</pubDate>
            <atom:updated>2022-10-10T06:19:36.266Z</atom:updated>
            <content:encoded><![CDATA[<p>Previous Story: <a href="https://medium.com/@cocm1324/implementing-cache-with-go-71e29fcdaf7">Implementing Cache With Go</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*atsA6BHUva4mzahcvkKIYQ.png" /><figcaption>Some random enum that I wrote on Go project</figcaption></figure><h4>My Expectations on Enum</h4><p>After a couple Go projects, my project repositories are getting more and more complicated. In order to deal with it. I split the codes into different files. One of the methodology of splitting was make enum to group up every constant values in one file.</p><p>Before I got to know Go, I use to write TypeScript. Check out following TypeScript code snippets for enums.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a4516f06ca9f43479858f9308790f41/href">https://medium.com/media/2a4516f06ca9f43479858f9308790f41/href</a></iframe><p>Easy eh? TypeScript enums syntax is clear and well defined. There are not much to explain. Just use keyword ‘enum’ followed by its name. Items without values will be set as integer starting from 0, or can use string value.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b21f1f11b0ede5faac1ae7b78f9646c/href">https://medium.com/media/7b21f1f11b0ede5faac1ae7b78f9646c/href</a></iframe><p>Usage on TypeScript is also tidy. I can use the name of enum as type, so that we can use it when defining var/functions types. Also the items the enum holds can be accessed as members of enum type.</p><p>The same traits can be found on <strong>Java </strong>and<strong> C#</strong>. It acts as good syntax sugar to avoid magic strings in code and group up constant values with same purpose to single type.</p><p>I expected the same or similar feature on Go.<strong> However,</strong> it didn’t. Compared to TypeScript what I used right before, it seems less natural because it is just constant with custom type, no enum keyword. Check out the next section.</p><h4><strong>What They Say about Enum in Go</strong></h4><p><a href="https://www.educative.io/answers/what-is-an-enum-in-golang">What is an enum in Golang?</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ea619365c3b2e06abbc1bd5a6d57914/href">https://medium.com/media/9ea619365c3b2e06abbc1bd5a6d57914/href</a></iframe><p>When you google “golang enum” or “go enum”, one of documents you get is like above. You can see 2 things;</p><ul><li>a type definition “Direction”</li><li>a series of constants typed as “Direction” and given a value with “iota” keyword.</li></ul><p>When I first see this, I felt weird about it because it was just constant with custom type, not a well defined enum keyword by language itself.</p><p>Usage is kind of same with other languages but since enum items are constants, I could not use &lt;EnumType&gt;.&lt;item&gt; kind of syntax. I only use &lt;item&gt;.</p><p>After all, I accepted it as a philosophy of Go; trying to simplify its syntax. However when I tried to use it in real project, I encountered some weird situations.</p><h4>Some Weird Situations</h4><p>The situations that I encounter were these; too many files and folders, names of enums got too long and sometimes it overlaps with other things, and there were chance of too many imports. Overall, using enum was bad for readability</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*kFibqEltEe1ipOSI_IRn3w.png" /><figcaption>Folder Structure that I Used Before</figcaption></figure><p>Before diving into the situations. I have to explain the project structure that I used before. As you can see in the above picture;</p><ul><li>I made “enums” folder</li><li>I made each &lt;enum_name&gt; folder</li><li>I made &lt;enum_name&gt;.go files under each folder.</li></ul><blockquote><strong>Don’t follow this structure; I’m telling you that it is not right.</strong></blockquote><p>This structure(making enum folder to put all enum files) are pretty easy to find in other OOP language projects. I used to do like this in my previous Angular project; my senior taught me to write enums this way.</p><p>The only difference is there are wrapping folders for each enum files so that the enum file should have package name &lt;enum_name&gt;_enum in order to tell apart each one.</p><p>Without no doubt, I wrote enums like this in current Go project and encountered many weird situation.</p><p><strong>Situation 1: So Many Folders and Files</strong></p><p>As you can see in the previous picture, one enum requires one wrapping folder. This was necessary because I wanted &lt;enum_name&gt;.&lt;item_name&gt; usage.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1144b53293a074688fd7aa095a1eebf1/href">https://medium.com/media/1144b53293a074688fd7aa095a1eebf1/href</a></iframe><p>There are also some problems without wrapping folders. Putting all enums in enums package will cause</p><ul><li>Collision</li><li>Readability</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W3SFiAMiueWcjbR51fsw1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fpC4nYpOtpE3viT_5MM-4w.png" /><figcaption>Colliding Items (left) / Readability Issue (right)</figcaption></figure><p>Even if the above codes are in one file, it would be the same when you put two files in a same folder and mark it as same package. As you can see, there are items called ‘Running’ for two different enum. Since it is not a enum item but constants, it will collide with its name.</p><p>Also, take an example when you use enum somewhere else. As you can see on the above code, it is hard to find what ‘Running’ and ‘Stopped’ means by just looking it. How about ‘Database.Running’ or ‘Threadmill.Stopped’? Much better to read.</p><p>These are why I choose to wrap each enum code with its package, <strong>ended up with so many folders and so many files to write or search around.</strong></p><p><strong>Situation 2: Keywords Get So Long or Overlaps</strong></p><p>Usually if I want to implement some API about something, I would make handler file for handle http or other request, enum file for constants, repository file which controls database or cache, etc. All these will have names related to the object that I want to implement.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c1c73a1914e06f631a6650e8c2b3521/href">https://medium.com/media/8c1c73a1914e06f631a6650e8c2b3521/href</a></iframe><p>For example, if I want to implement apple API, the naming of each component would be like follows; “repository.AppleRepository”, “enum.AppleEnum”, “handler.AppleHandler”.</p><p>I can use some abbreviation or removing some redundant words, it could be possible to cause readability problems for others. But apart from these problems, this doesn’t look to be some elegant solution.</p><p><strong>Situation 3: So Many Imports</strong></p><p>This one could be the minor one; If I wanted to use enums, I had to have additional one lines for each enums because each enums were separated as packages.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4994d175186dd5328d08ec9295e417a/href">https://medium.com/media/f4994d175186dd5328d08ec9295e417a/href</a></iframe><p>Some would argue it is not a problem at all, but for me, this possibility of so much extended import section seemed awful. I thought there could be some much simpler and elegant solution.</p><h4>Solution: Change the Package Structure</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*641E1wD_iNKBKUyx-9O5tw.png" /><figcaption>The official http package shows best practice for enum use</figcaption></figure><p>The moment when I glimpse the solution was when I was using some <a href="https://pkg.go.dev/net/http">net/http</a> package which is Go’s out of box package for http server feature. It has some constant values of http response codes and as you can see from the above picture, it is included in http package and named as prefix of type followed by item: &lt;package_name&gt;.&lt;enum_name&gt;&lt;item_name&gt;.</p><p>After examining the structure of http package, I noticed this; variables and constants related to some object are “good” to be placed in the same package. Not just enums, handlers, repositories, etc. are good to be regrouped to a single package.</p><p>I could not find some official documentation about the range of one package should have but as <a href="https://go.dev/doc/effective_go">Effective Go</a> says:</p><blockquote>Java programs are written in Java, not Go. On the other hand, thinking about the problem from a Go perspective could produce a successful but quite different program</blockquote><p>The biggest error that I made was I tried to use Java style of project structure for Go code. Check out the changes that I have made.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*ZLip3j0SWX8Jx70HumexzA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*gMoU6QRbFYNAtzMSit0_eA.png" /><figcaption>Some Java style project structure I tried (Left) / The fixed one (Right)</figcaption></figure><p>Note that some names are changed(coin-&gt;cryptocurrency). You can see the clear difference between two. Previous structure has handlers, enums, repositories that are about same object(coin) separated across different packages. Now, those are grouped into a single package called cryptocurrency.</p><p>This change address all three situation addressed.</p><ol><li><strong>So many folders and files</strong>: As you can see from above picture, it clearly reduced folders and files.</li><li><strong>Long and overlapping keywords</strong>: “cryptocurrency_enum.CryptocurrencyEnum” to “cryptocurrency.TypeCryptocurrency”. Seems not a big change but much clearer and no redundancy. Also. It applies for every other components such as “handler.CryptocurrencyHandler” to “cryptocurrency.Hander” or “repository.CryptocurrencyRepository” to “cryptocurrency.Repository”.</li><li><strong>Too many imports</strong>: Squashed to single package.</li></ol><p>I thought this solution is much fitter to Go syntax and satisfied.</p><h4><strong>Conclusion</strong></h4><p>I had some reminiscent of TypeScript(or Java) style folder structure, and applied it to Go programming, experiencing some weird situations. Enum was the one that caused noticeable problems; causing unnecessary folders and files to be created, making names too long and to collide with each other, and unnecessarily long import lines. I found the error from the folder structure and fixed it to new structure that is much suitable for Go.</p><p>I think both styles have pros and cons. It is just shows the difference in philosophy. Interesting one.</p><p>Thanks for reading. Go stories will continue.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3460951bbbf2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Frontend Dev’s Unity Game Dev Experience]]></title>
            <link>https://medium.com/@jaeeunchodev/frontend-devs-unity-game-dev-experience-6315a96f9048?source=rss-c17d6cda7c7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/6315a96f9048</guid>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Jaeeun Cho]]></dc:creator>
            <pubDate>Fri, 12 Aug 2022 06:39:14 GMT</pubDate>
            <atom:updated>2022-08-12T07:37:23.207Z</atom:updated>
            <content:encoded><![CDATA[<h3>Frontend Dev’s Game Dev Experience</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*i4t-uid9ShC4PqDE4vGYMA.gif" /><figcaption>My first game, it is just clone though</figcaption></figure><p>Seems too late for me to switch from web dev to game dev, but I wanted to do it anyways since I am game enthusiasts. I started to learn Unity. As a web developer, it was bit odd that many concepts of game dev in Unity are much similar to those in frontend. Heres story of my experience of finishing 2 different tutorials for game dev.</p><p>Before we start, here it is. <a href="https://kickpunch-tech.herokuapp.com/mchase/">Click this to Play</a> the result. It is bit simple, doesn’t work for mobile, and no leader boards, but it taught me a bird-eye view of Unity and game dev. I will work on it.</p><p><strong>Two Tutorials that Lead Me to Here</strong></p><ul><li><a href="https://youtu.be/Rs_rAxEsAvI">Self-Driving car with JavaScript Course</a></li><li><a href="https://youtu.be/gB1F9G0JXOo">Learn Unity — Beginner’s Game Development Tutorial</a></li></ul><p>Before I start, I want to disclosure two wonderful tutorial courses. Check out <a href="https://www.youtube.com/channel/UC3XGlNq8O5hZlZBJlSFB4jg">Radu </a>and <a href="https://www.youtube.com/channel/UC5c-DuzPdH9iaWYdI0v0uzw">Awesome Tuts</a> who are the creators of these tutorials and also <a href="https://www.youtube.com/c/Freecodecamp">freeCodeCamp.org</a> channel which hosted these tutorials.</p><p>So, what are these?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*1ngxdal1yQ4Csok4M7oUMg.gif" /><figcaption>Self Driving Car with JavaScript</figcaption></figure><p><strong>The first video is about implementing self driving car with HTML / CSS / JS</strong>. There are two major subject in this tutorial. 1) making games out of JavaScript. 2) making NN(Neural Network) to solve the game. However, but for this story, I want to focus only to 1) making games. Maybe later for my study of NN in another story.</p><p>When you see the above demo, you can find a swarm of blue cars and red cars. Red ones just moves up, blocking the lane, and blue one tries to move pass the red one. The game aspect of this example is implementing blue car’s behavior; implementing collision, detection line(which is 5 yellow line that attached to preceding blue car), and implementing 4 car movement input(forward, backward, turn left, and turn right).</p><p>I’m not going deep into code. The important thing is that I learned about <strong>Game Loop</strong> in this tutorial. As JS developer, I used to see the view as initialization and event. Take a case where we implement webpage with JS. I would implement initial view with HTML file, and set event to change state of each element with event such as button click, scrolling, mouse-over or something. However, the game loop was something new. Though events that I mentioned are fired upon ‘event-loop’ in browser, concept of firing behavior function of element for each tick is what I think the most different thing between web and game.</p><p>After all, I started this tutorial to learn NN concept at first place but learned about important concept of game dev. With this concept, I moved on to the second one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*15rsIDUkbOhr7lGw1fGrkw.png" /><figcaption>Me following the Unity tutorial</figcaption></figure><p><strong>The second video is about tutorial to implement simple 2D game with Unity</strong>. It is called Monster Chase; Zombies and ghosts come towards you and you have to jump it over to evade.</p><p>From this tutorial, I learned about these in respect to prior knowledge of frontend dev:</p><ul><li><strong>C#</strong>: Of course, I should learn new language for Unity. The truth is, learning tutorial level C# was the easiest of all. Many concepts were similar to JS.</li><li><strong>Assets</strong>: I had to prepare for assets and the tutorial did it for me. Most of them was sprite images, but there could be 3D model, music, sound effects, etc.</li><li><strong>Scene</strong>: Scene is the biggest unit of game. It holds every object and logic. It was similar to one HTML file in website. When we access to one url, browser loads every element and logic from that HTML file. Same thing happens when one scene is loaded.</li><li><strong>Hierarchy, GameObjects, Prefabs:</strong> Game objects are what follows after Scene. It is placed in scene. It could be player, monster, camera, lightings, canvas, or every object inside scene. It could be nested to other game objects which forms hierarchy. Game objects can be snapshotted as prefabs and used later in anywhere. Similar to DOM elements in web(but there is many differences because of the following concept ‘Components’)</li><li><strong>Components</strong>: Components are attached to game object. It defines behavior of attached game object. For example, a RigidBody components gives mess and gravity to game object when attached. We can make new component with C# scripting, and this is where we should manage the lifecycle and game loop. I cannot tell the comparison with web because there is no 1 to 1 corresponding things for components. Components sometimes acts like attribute in DOM, or sometimes tag. Actually, components cover much wider features.</li></ul><p>Some patterns and approaches of OO(Objective Oriented) also showed similarities</p><ul><li><strong>Component Life Cycle Management</strong>: For React or Angular developers, components and its lifecycle management would seems familiar. Unities components use the same approach. We can define behavior of each lifecycle changes of Unity component like we did in React.</li><li><strong>Services</strong>: Also for React and Angular developers, implementing services, make it singleton and injecting it to components are usually-do jobs. Game manager in Unity does the same. It is initialized once and used to many components passing singleton states and providing utility functions.</li></ul><p>Although it was 7 hour-long video, it felt bit easy because concepts are similar to those on web. After finishing it, I felt confident about learning furthermore game dev with prior knowledge of frontend dev.</p><p>I made some improvements to tutorial such as removing redundancies or adding movement on background. Also compiled it to WebGL and easily uploaded it into internet. However there are some rooms for improvement such as mobile support, scoring, leader board, etc.</p><p><strong>Conclusion</strong></p><p>After finishing 2 tutorial, I felt that game and frontend seems a lot similar to each other. Is this because of both of them works as human interface to system or because of the object oriented style that both of them taken? Maybe both. I think the goal of good presentation and interaction to user as well as good tools for dev made both of them looks alike each other.</p><p>Game dev stories will be continued.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6315a96f9048" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Cache With Go]]></title>
            <link>https://medium.com/@jaeeunchodev/implementing-cache-with-go-71e29fcdaf7?source=rss-c17d6cda7c7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/71e29fcdaf7</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[cache]]></category>
            <dc:creator><![CDATA[Jaeeun Cho]]></dc:creator>
            <pubDate>Fri, 22 Jul 2022 08:32:07 GMT</pubDate>
            <atom:updated>2022-10-10T06:17:31.153Z</atom:updated>
            <content:encoded><![CDATA[<p>Previous Story: <a href="https://medium.com/@cocm1324/a-newbie-gophers-server-developing-experience-6c5c2b942ad0">A Newbie Gopher’s Server Developing Experience</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*01LZ53DZfUAqe8FsivPtdQ.png" /><figcaption>Client-Server Caching</figcaption></figure><h3><strong>Introduction</strong></h3><p><strong>Concept</strong></p><p>Cache is one of the important concepts in computer science. Think of a component that need some external resources, it request the resources to external source, receive it, and use it. These steps takes some time. When the component needs the resources again, it is inefficient in time-wise to request it again. Instead, the component can save the request results somewhere locally and use it again. Using local data would be always faster than requesting external one. These strategy is basic concept of cache. We can find these examples in memory, CPU cache, and server caches like <a href="https://redis.io/">Redis</a>.</p><p><strong>Different Use Cases</strong></p><p>Cache in web service is used to reduce latency of data request. Instead of querying DB, it saves the first query execution and use it afterward. There are some different situations for caches depends on the characteristics of data. There can be relatively static data such as stats, calculation result. There also can be frequently changing data such as comment section or SNS.</p><p>The best case is caching some rarely changing data. Take monthly statistics. Stats of last month will not be replaced for month. If we cache it, we may not have to check DB for month.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2PsFbsJt_AiCCFHC0YpjqA.png" /><figcaption>Some Dumb Design</figcaption></figure><p>For fast changing data, it’s better to take cautions when there are duplicated servers. Check out above design. Take some comment section service example. There are some case that User A comment something, then A decides to delete the comment, User B tries replies the comment. There are some cases where A and B request to different server. A’s deletion may not be propagated to B’s server’s cache. The result will be something like this; Cache A, Cache B has different data and DB doesn’t know which one is the truth. The integrity of data has broken here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*amm206uyJl16zStD01S-hA.png" /><figcaption>Better Way</figcaption></figure><p>In that case, using single external cache like above picture will do the problems. Redundant servers only uses single cache.</p><p><strong>Restrictions</strong></p><p>Cache is faster than DB but it is significantly lesser in size. This is because DB stores data in drive, cache stores data in memory. They follows the same characteristics of each. They follows the same characteristic of volatility; If host stops, all data will be lost for cache, but not a single one for DB.</p><p>Since cache sits on memory, its space is restricted, and it need to choose which data to cache. Back in CS lecture, I heard some words like LRU(Least Recently Used), LFU(Least Frequently Used), and FIFO(First In First Out). These are the “which one to choose” criterions, and it is called eviction policy.</p><h3><strong>Design &amp; Implementation</strong></h3><p><strong>Requirement</strong></p><ul><li>Key-Value Storage: Cache should provide read function that input key and output value as well as write function that input key, value. These functions should be done in average O(logN) time where N is number of key.</li><li>LRU Eviction Policy: Since cache is restricted in space, some data should be evicted if cache is full. Implement with LRU algorithm.</li><li>Time To Live(TTL): Each key-value has TTL. If TTL is passed, it should be evicted.</li></ul><p><strong>API Design</strong></p><p>Key-Value storage means that, if I request key, cache will return value of those key if exists. Hash-map abstract data type is the same kind. Take an application that provides following API concept.</p><pre>func Get(key string) (hit bool, value []byte)<br>func Put(key string, value []byte) (hit bool)</pre><ul><li>Get: A read with key API. If provided key exist in cache, return equivalent value. If not, it just returns hit=false. For LRU policy, the key will be marked the most recently used; that makes this key the most far ordered from eviction.</li><li>Put: A write with key API. If provided key exist, value will be replaced with new value. If not, it will just create new key-value to storage. The execution of this function can cause overflow since it can add one data. In that case, by the LRU policy, the least recently used key-value will be evicted. The newly added/modified key will be marked the most recently used.</li></ul><p><strong>Data Structures</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sjAQ67mi_g5Nqd4jNE6FJA.png" /><figcaption>Design Concept</figcaption></figure><p>I used two different data structure; hash-map and doubly linked list. This is to implement feature of both key-value read/write and LRU policy.</p><ul><li>Hash-map: Hash-map is the most widely used key-value data structure. It is provided as ‘map[&lt;type&gt;]&lt;type&gt;’ in Go as out of box data type.</li><li>Doubly Linked List: LRU cache can be implemented with doubly linked list.</li></ul><p>Binding these two data structures can provide both key-value feature and LRU policy. Refer to above picture of design concept. Hash-map’s key would be string key, and value will be pointer to linked list’s node. The node will hold value of the key.</p><p>If user called Get(), this cache application will search key in hash-map, follows the pointer to reach one node in linked list, get values, do LRU things and returns the value to user.</p><p>Likewise, if Put() is called, it search the key in hash-map, follows the pointer and replace the value, do LRU things, or insert new key to hash-map, and insert new node to linked list.</p><p><strong>Concurrency Control</strong></p><p>Since cache is designed to be accessed much frequently, there will be multiple access at the same time and there always exists a chance of concurrency problem.</p><p>In my design, there exists two different data structures, and it doesn’t always be synchronized. In executions, there is a tiny time gap between modification of hash-map and modification of linked list. Check out following example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JOLNX48ULPuWMJwhcKqwxg.png" /><figcaption>One Case of Concurrency Problem</figcaption></figure><ol><li>It starts with this condition: currently cache is full, and least recently used key is 1. That means, if new key is added, key 1 and the equivalent value will be evicted.</li><li>User A calls Put() with new key 101. Hash-map checks the key and finds out that 101 doens’t exist. It decides to evict 1 and add 101 to cache.</li><li>In the meantime, User B calls Put() with key 1. Hash-map confirms key 1 exists, and decides to modify the value.</li><li>A’s call proceeds. It deletes node 1 from linked list, and delete key 1 from hash-map.</li><li>Just right after that happens, B’s call tries to access node 1’s address and finds out the address is out of allocated memory. It panics and application goes down.</li></ol><p>The most easy way to prevent this from happening is to use <strong>Mutex</strong>. Checkout following code.</p><pre>func (s *CStorage) Get(key string) (data []byte, hit bool) {<br>  <strong>s.mutex.Lock()<br>  defer s.mutex.Unlock()</strong></pre><pre>  n, ok := s.table[key]<br>  if !ok {<br>    return nil, false<br>  }</pre><pre>  if n.ttl.Before(time.Now()) {<br>    s.evict(n)<br>    s.size--<br>    return nil, false<br>  }</pre><pre>  return n.data, true<br>}</pre><p>This code is function definition of Get(). We can see there is mutex lock code in the first line, and mutex unlock code as defer(which is a Go keyword that postpone line execution to the end of this function) in the second line. These codes are applied to all other data storage accessing functions like Put, Delete Clear, and etc.</p><p>By using mutex, each execution will not be affected by others, ensuring safe data access.</p><p><strong>Time To Live</strong></p><p>Currently TTL is implemented as passive method. That means, if data access functions(Get, Put) are executed, it will check TTL is expired and deletes it. Also it means even if node is expired, it will still exists on data structure.</p><p>This method doesn’t require a big CPU execution of traversing all nodes periodically, but cache is likely to hold expired values.</p><p>Most of the time, it will be okay because expired node is likely to be ‘Least Recently Used’ state. However, it would be great to have functions to cleanup expired nodes through the data structure, so I made RemoveExpired() function.</p><pre>func (s *CStorage) RemoveExpired() int64 {<br>  var count int64 = 0<br>  for key, value := range s.table {<br>    if value.ttl.Before(time.Now()) {<br>      s.Delete(key)<br>      count++<br>    }<br>  }<br>  return count<br>}</pre><p>This function will periodically called to cleanup all expired nodes.</p><p><strong>Results</strong></p><ul><li>github.com: <a href="https://github.com/cocm1324/cstorage">https://github.com/cocm1324/cstorage</a></li><li>pkg.go.dev: <a href="https://pkg.go.dev/github.com/cocm1324/cstorage">https://pkg.go.dev/github.com/cocm1324/cstorage</a></li></ul><p>The implemented Go packages can be imported by other Go projects. Also, I made standalone cache application that provides gRPC API. Check out <a href="https://github.com/cocm1324/gcache">this repository</a>.</p><h3><strong>Conclusion</strong></h3><p>I had this great chance to revisit concept of cache, and implement it with Go. Cache is good tool to reduce latency of component. It is restricted in space but it is faster.</p><p>Implementing actual cache module is can be done with hash-map and doubly linked list. There was some tricky problems with concurrency, so I had to use mutex. Also, I mixed passive and active way to remove expired data.</p><p>As is widely known, it is different just reading concept from textbook then actually implementing it.</p><p>The Go stories continues.</p><p>Next Story: <a href="https://medium.com/@cocm1324/weird-go-enum-leads-to-lesson-different-project-structure-3460951bbbf2">Weird Go Enum Leads to Lesson: Different Project Structure</a></p><p><strong>References</strong></p><p><a href="https://medium.com/@ksholla20/design-and-implement-a-caching-library-e456b0f6449f">https://medium.com/@ksholla20/design-and-implement-a-caching-library-e456b0f6449f</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71e29fcdaf7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Newbie Gopher’s  Server Developing Experience]]></title>
            <link>https://medium.com/@jaeeunchodev/a-newbie-gophers-server-developing-experience-6c5c2b942ad0?source=rss-c17d6cda7c7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c5c2b942ad0</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[cache]]></category>
            <dc:creator><![CDATA[Jaeeun Cho]]></dc:creator>
            <pubDate>Mon, 27 Jun 2022 09:50:56 GMT</pubDate>
            <atom:updated>2022-07-23T07:20:36.906Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Newbie Gopher’s Server Developing Experience</h3><p>Previous Story: <a href="https://medium.com/@cocm1324/started-to-getting-used-to-go-b53c519ddfff">Getting Used to Go</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mHxPsdVPwb4xfRh9_ksNDg.gif" /><figcaption>Some Coin’s Price Prediction Model</figcaption></figure><h3><strong>Introduction</strong></h3><p>After playing a bit with Go, I decided to do something bigger; to make web service of something. Since it is said Go is good for server development, I think it would be great to implement some web server that manages data and serve them.</p><p>At that time, I did some activities in my university’s alumni group. The group was about financial investments, so I had chances to have some coffee chats with couple fund managers. One assets that we talked a lot were cryptocurrencies</p><p>One fund manager told me that it would be fun to build some web service out of his logic and my SW skills. Here’s what we have gone through;</p><h3><strong>Idea</strong></h3><p>I’m not going to be explaining some wacky mechanism of cryptocurrency internals or fundamentals. Over simplified conclusion of our logic is this;</p><blockquote>Total burned USD might be related to cryptocurrency’s prices</blockquote><p>What is total burned USD? Ever heard of stock buyback? Same thing for crypto is burn. Some cryptos are issued by certain subject and the subjects buyback issued crypto with USD or other traditional currencies.</p><p>We thought it would be fun to track long term data of price and burn. Furthermore it might be a great research if we make relation equations out of it, and digitize how it matches.</p><p>In order to do this, basic steps are same as follows;</p><ol><li>Periodically fetch price and burn amount</li><li>Stack it someware to make historical data</li><li>Calculate prediction from historical data</li></ol><h3><strong>Design</strong></h3><p>After discussing this idea with the fund manager, I started to draw some simple overview of system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5lXEJQ6jOER4phjmA7bZiA.png" /><figcaption>Simple overview of architecture and tasks</figcaption></figure><p>Client would be simple HTML/CSS/JS to provide view to user. Client will request data to server, and server will provide data. Server has various role of managing, caching, fetching, calculating data.</p><p>Here’s 2 major task that happens</p><p><strong>Purple Task: Data Fetching and Processing</strong></p><ol><li>Server periodically fires purple task with scheduler(once a week)</li><li>Fetch data from external sources</li><li>Process data: convert to db data, calculate price prediction model</li><li>Cache data: since the data is relatively static(it updates once a week), cache could be a good choice. Refer to <a href="https://pkg.go.dev/github.com/cocm1324/cstorage">this package</a> that I implemented</li><li>Save it to DB: even if we have cache, the true data should be stored to persistent storage. DB is the choice</li></ol><p><strong>Yellow Task: User Lands to Web Page</strong></p><ol><li>User visit web page and JavaScript logic will call server to get data.</li><li>Server checks cache first. If hit, move to 4th step</li><li>If cache doesn’t hit, server will retrieve data from DB, save it to cache</li><li>Response with data</li></ol><h3>Some Learnings</h3><p>Since basic idea of this projects are not from me, I thought it would be better not to disclosure every details of it, so I am not giving repository of this project.</p><p>Instead, I’m introducing some key learnings of this projects</p><ul><li>Basic HTTP Server Design Patterns</li><li>Use of Cache</li><li>Use of Go Package Publishing</li></ul><p><strong>Basic HTTP Server Design Patterns</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*16CjQrkDNd5s7sBg-_MYSA.png" /><figcaption>Internal folder of satellity repository</figcaption></figure><p>While I am developing server, I heavily referenced the structure of <a href="https://github.com/satellity/satellity">satellity</a>. Key folders to watch are <strong>controller, model </strong>which are basically representing MVC pattern.</p><p>Go files in controller acts as controller for http server. If request comes, it parses, checks error, and calls model function according to request method. Go files in model acts as source of data structure and provide functions to modify or retrieve it.</p><p>I followed the same pattern for my project.</p><p><strong>Use of Cache</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_nJSqiruZ49i7s7pcPq9Xg.png" /><figcaption>Cache</figcaption></figure><p>Next key learning is use of cache. It was closely related to our business logic that the data updates once a week. In that case, cache is pretty good because user will request same data for entire week.</p><p>Cache is temporary storage that smaller but faster than database. For handling frequent and static request, using cache will enhance performance. Cache have some fallbacks with data integrity when data changes frequently but this is not the case for us.</p><p>I implemented simple key-value store Go package called <a href="https://pkg.go.dev/github.com/cocm1324/cstorage">CStore(abbreviation of Cache Store)</a> and used it in server.</p><p><strong>Use of Go Package Publishing</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*ArSyJysm9K8Btm5VFTzzCg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*hboJIkTRJU_pZKWK03751g.png" /><figcaption>Published Packages: CStorage(left) and PRegression(right)</figcaption></figure><p>Last key point of learn is Go package publishing. Since I used Node.js for couple years, I had similar experience of publishing some useful functions to <a href="https://www.npmjs.com/">npm</a>. Same here, I made 2 packaged published during this project.</p><p>First one is Cache Storage (<a href="https://pkg.go.dev/github.com/cocm1324/cstorage">https://pkg.go.dev/github.com/cocm1324/cstorage</a>). Cache would be useful to other server kind of projects.</p><p>Second one is Polynomial Regression (<a href="https://pkg.go.dev/github.com/cocm1324/pregression">https://pkg.go.dev/github.com/cocm1324/pregression</a>). Polynomial regression served as great utility for data processing in this project but I thought this package can be used in another financial or data processing project in the future.</p><h3>Conclusion</h3><p>As a newbie Gopher, I learned a lot from implementing server with Go.</p><p>I discussed idea with fund manager, draw architecture from the idea, implemented it. Now, about 100 alumni in my group visits the website regularly.</p><p>I learned basic pattern of Go server, advantage of using cache with static data, and how to publish package for future use.</p><p>Go story will return;) Thanks for watching.</p><p>Next Story: <a href="https://medium.com/@cocm1324/implementing-cache-with-go-71e29fcdaf7">Implementing Cache With Go</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c5c2b942ad0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Regrets of My Early Careers]]></title>
            <link>https://medium.com/@jaeeunchodev/regrets-of-my-early-careers-f967b49a406e?source=rss-c17d6cda7c7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f967b49a406e</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[careers]]></category>
            <dc:creator><![CDATA[Jaeeun Cho]]></dc:creator>
            <pubDate>Wed, 01 Jun 2022 06:31:45 GMT</pubDate>
            <atom:updated>2022-06-01T08:03:40.302Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IEXz3XWoa7YCI8FVnBQDsQ.jpeg" /><figcaption>Way Home</figcaption></figure><p><strong>Introduction</strong></p><p>I started career with software engineer and I’m doing it for almost 3 years. I like it a lot because there are tons of things to learn and each learnings widen my eyes. I think I will not stop doing software engineering even after no one seeks for my skills.</p><p>Today, however, I quit from last company and seeking another software engineer job. Lack of learning opportunity is the main reason I decided to move on.</p><p>I took some time to review my experience and thoughts from my last 2 companies, and I came up with some regrets of company and myself.</p><p><strong>First Company</strong></p><ul><li>Lack of learning opportunity</li><li>I didn’t tell what I wanted</li></ul><p>First company was based on the US. Most of software engineers were working in S. Korea location, and some of lead engineers, managers were in Virginia. Most of senior engineers were highly experienced and communication between different locations were done seamlessly. I’m sure that there were bunch of learning opportunities.</p><p>Then, what is ‘Lack of learning opportunity’ at the start of this section? I was a half software engineer.</p><p>My primary task was <strong>customer service</strong>, even though I applied for software engineer and I entitled as software engineer.</p><p>At that time, enthusiasm was me. I didn’t refuse to do it and at the same time, I lied to myself; “doing customer service is good because it will give me software engineer skills”. These lies were partially right since I was doing software product customer service.</p><p>As time goes by, I had some chance to participate in software engineering projects while doing primary tasks(customer service). Doing project was ton of fun and I think I grew up so much at this period.</p><p>However, there was some limit of doing software project because of my primary task. I started to think my learning opportunity was keep restricting. Eventually this reality made me to quit from the first company.</p><p>I didn’t told this to my manager until the last time. So he was bit surprised. He told he will arrange other positions, but since I already made my mind, I declined it and quit.</p><p>Today, I have two regrets about this experience. First, company didn’t tell the truth about ‘software engineer’ position. Second, I didn’t tell my thoughts of my position until last time.</p><p>What if company told me that ‘software engineer’ can be a position doing customer service jobs at the beginning? I could have chosen another company or I could asked if it can be rearranged to software engineer project works.</p><p>What if I told my thoughts of customer service earlier to my manager when I felt the limits. He would tried to arrange other position as he tried at the last time. Maybe he could have solved the problems.</p><p>From these experience and reviews, I learned that <strong>communication is the most important thing</strong> for both side; employer and employee. I believe thorough conversation will make it better to set goal for both me and company.</p><p><strong>Second Company</strong></p><ul><li>Lack of manager, senior</li><li>Lack of knowledge and experience</li></ul><p>Second company was startup company trying to launch freight platform service. When I started work at there, there were team of 10+, including 3 software engineer, one of them is senior engineer of 20+ experience. I was junior engineer and my position was Node.js server engineer.</p><p>I can tell that there were two phases of period in my experience. The first phase was literally ‘startups’ phase, and the second phase was ‘slowly breaking down’ phase.</p><p>When I first landed there, the team(since it is startup, there was only one team) aims to build up startup culture. It seems dev members and director were kind of startup guys and enthusiastic in solving our target problem. Other team members were not kind of startup guys but experienced and knew what they should do.</p><p>Everything seems great. For half years, I felt startup spirit of problem solving and start as lean and adopting feedbacks without hesitant.</p><p>Suddenly, however, everything changed. I will not tell what exactly happened, but my senior engineer made some mistakes and got fired. Also, CEO decided to hire manager who was good at outsourcing, not building a team or start from scratch. I off-boarded from there several month later, and I heard that the company was closing its business.</p><p>For that several month, I struggled to solve problems that way overwhelms me without any help. Two thought came to my mind; A resentment that company could not arrange new senior for junior me, and regrets that I don’t have enough skills and knowledge to turn things back.</p><p>I learned that building up team, leading engineering project is not an easy thing from this experience. I was bit childish about the resentment part; I understand how it is so hard to get senior engineer these days. Hopefully, both company and me would be prepared next time.</p><p><strong>Conclusion</strong></p><p>I dreams about one day, I team up with good and experienced people and build something exciting. Regrets felt yesterdays will be great jump ups for tomorrow.</p><p>I learned about the importance of communications for both employer and employee, significance of proficient skills and knowledge.</p><p>For the next post of this series, I will be posting what skills that I have learned from my early careers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f967b49a406e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Started to Getting Used to Go]]></title>
            <link>https://medium.com/@jaeeunchodev/started-to-getting-used-to-go-b53c519ddfff?source=rss-c17d6cda7c7e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b53c519ddfff</guid>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Jaeeun Cho]]></dc:creator>
            <pubDate>Tue, 31 May 2022 08:54:44 GMT</pubDate>
            <atom:updated>2022-06-27T09:52:12.361Z</atom:updated>
            <content:encoded><![CDATA[<h3>Getting Used to Go</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sbxRHaK3oMfItMoCFVXYNQ.png" /><figcaption>Doing some Go coding</figcaption></figure><p><strong>Introduction</strong></p><p>I used JavaScript and Node.js at projects for last 3 years. I started as Angular developer at my first career, used Node.js in personal projects, and developed TypeScript servers. I really get used to Node.js. Not like guru but I’m sure I can implement many things from it.</p><p>After 3 years, I came up with one idea; Like I get used to Node.js and JavaScript, I <strong>should revisit <em>“how to get used to some other language and concept”</em></strong>.</p><p><strong>Why Go</strong></p><ul><li>Good for server developing</li><li>Binary executables</li><li>Statically typed language</li></ul><p>First step was to choose what language to learn. I choose Go. There were couple reason for this.</p><p>First reason is that Go is good for server developing. These days, I’m really interested in server application developments and usually do server projects. Why I like to do server programming is there are much different systems to learn. Go has good server developing packages out of box. Compared to Node.js where you should download all the different packages before starting developing servers, Go would be pretty lightweight and not much to learn.</p><p>Second is Go outputs binary executables. I usually use Docker to deploy applications to servers since it ensures identical environment for application and it can be used as scalability and availability provider. The problem I experienced with using Node.js + Docker was that final output of Docker image is big. Since Node.js alone is big application, and its application sometimes required a lot of packages, its image sizes sometimes reaches almost half GBs. Compared to that, Go is much better. It usually has 2MB kind of image size when used with BusyBox or Alpine image(most lightweight linux image), makes it simpler to use with Docker.</p><p>Finally, I thought I should learn how to use typed language. Dynamic types of JavaScript was useful when dealing structured data with JavaScript Object. However, it also had some tradeoffs of performance and readability. Even if TypeScript provides some typed-like experience, it has limits. Go is static typed language, and I thought it could be a good option to learn how to improve performance and readability using static typed language.</p><p><strong>Plans to Do It</strong></p><ol><li>Read good docs, watch tutorials, and refer to references</li><li>Starting New Project</li></ol><p>How should I learn Go? I came up with these;</p><p>I like to start leaning new concept from top-down approach, which means starting from conceptual videos and tutorials, and deep down to official documents and other project references. For Go, I personally started with following;</p><ul><li><a href="https://go.dev/tour/welcome/1">tour of go</a>: Go official interactive tutorial</li><li><a href="https://www.youtube.com/watch?v=SonwZ6MF5BE&amp;t=52s">Traversy Media Youtube Tutorials</a>: a great Youtube channels to start all kinds of web programming concept</li></ul><p>These gave conceptual understanding of Go. I kept on going with deeper docs, tutorials, and reference projects.</p><ul><li><a href="https://go.dev/doc/effective_go">effective go</a>: Go official document of how to write good Go code</li><li><a href="https://github.com/golang-standards/project-layout">project layout</a>: a common project layout repository to reference</li><li><a href="https://github.com/satellity/satellity">satellity</a>: a good reference REST API project written in Go</li></ul><p>Starting a simple project would be great boost up for learning. After doing some readings written above, I jumped right into projects.</p><ul><li><a href="https://github.com/cocm1324/pregression">pregression</a>: simple polynomial regression package</li><li><a href="https://github.com/talenthandongsite/bulk-download">bulk-download</a>: simple web based downloader</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oqAeBlhXc74OmvMmt5gftQ.png" /><figcaption>Example of pregression</figcaption></figure><p>First project was ‘pregression’, at that time I was doing small project that process some historical data of cryptocurrency and predicts future price. The core was polynomial regression model and I decided to implement it with Go. I will posting ‘pregression’ and the prediction project later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*_DDmLCPo2OjxPihr-Y1g-Q.gif" /><figcaption>Example of Bulk Download</figcaption></figure><p>Second project was ‘bulk-download’. It is simple web service that takes URL pattern from user and bulk download and zip it to provide download. One friend of mine was suffering from this tedious task, and asked me if I can automate it. So I did.</p><p><strong>Conclusion</strong></p><p>Now I think I’m ready to do some real projects with Go. Like I said above, I choose Go because it is good for server, it outputs binary when compiled, and it is statically typed language. I did reading and watching docs and tutorials, conducted simple project myself with Go.</p><p>I’m currently doing some bigger projects with Go, and also I’m going to post those in another article. Thank you for watching!</p><p>Next Story: <a href="https://medium.com/@cocm1324/a-newbie-gophers-server-developing-experience-6c5c2b942ad0">A Newbie Gopher’s Server Developing Experience</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b53c519ddfff" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>