<?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 Dimas Yudha Prawira on Medium]]></title>
        <description><![CDATA[Stories by Dimas Yudha Prawira on Medium]]></description>
        <link>https://medium.com/@prawira.dimas.yudha?source=rss-406ade1a4a88------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0cJ0nRgfSMHu5C8NM_nwbw.png</url>
            <title>Stories by Dimas Yudha Prawira on Medium</title>
            <link>https://medium.com/@prawira.dimas.yudha?source=rss-406ade1a4a88------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 25 Nov 2026 02:13:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@prawira.dimas.yudha/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[Enlarging System Design Cheat Sheet — Part 2]]></title>
            <link>https://medium.com/@prawira.dimas.yudha/enlarging-system-design-cheat-sheet-part-2-6e00d4e3aaeb?source=rss-406ade1a4a88------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e00d4e3aaeb</guid>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[cqrs-pattern]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[Dimas Yudha Prawira]]></dc:creator>
            <pubDate>Tue, 30 Jul 2024 10:34:15 GMT</pubDate>
            <atom:updated>2024-08-06T05:28:17.345Z</atom:updated>
            <content:encoded><![CDATA[<h3>Enlarging System Design Cheat Sheet — Part 2 : CQRS</h3><p>Mari kita lanjutkan pembahasan kita mengenai System Design Cheat Sheet.</p><p>tulisan sebelumnya bisa diakses <a href="https://medium.com/@prawira.dimas.yudha/enlarging-system-design-cheat-sheet-part-1-saga-and-cap-theorema-b5340230af09">https://medium.com/@prawira.dimas.yudha/enlarging-system-design-cheat-sheet-part-1-saga-and-cap-theorema-b5340230af09</a></p><p>Pada bagian ini kita akan membahas slide selanjutnya yaitu</p><p>3. Decouple read &amp; write for high performant system</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1LRaMDkz9447myK0E0AHcA.png" /></figure><p>Decouple proses read dan proses write bisa dilakukan untuk meningkatkan performa dari sebuah sistem terdistribusi, kenapa seperti itu?</p><p>Sebuah proses baik yang dilakukan oleh sistem yang menggunakan arsitektur microservice ataupun monolitik bilamana berhubungan dengan basis data (database) akan melibatkan 2 operasi yaitu baca dan tulis (read and write), baik itu hanya baca saja, tulis saja atau keduanya.</p><p><strong>a. Operasi baca (read operation).</strong></p><p>Operasi baca atau biasa disebut dengan <em>read operation</em> pada sebuah basis data adalah proses yang mengambil data dari basis data saat kita membutuhkannya. Analoginya adalah seperti pustakawan yang mencarikan buku berdasarkan permintaan.</p><p>Operasi baca sangat penting untuk pengambilan data. Operasi ini seperti perantara yang bertugas untuk berkomunikasi dengan sebuah basis data, mengambil data yang diminta, lalu menyajikannya kepada pengguna, atau ke aplikasi.</p><p>Operasi baca ini bukan hanya sekadar pengambil data! Operasi baca juga memastikan bahwa batasan atau kondisi yang diberlakukan pada data tetap dipertahankan.</p><p>Operasi baca merupakan operasi yang aman (safe operation), artinya proses pembacaan serta pengambilan data tidak akan membuat perubahan apa pun pada data yang diambilnya. Pada basis data, operasi baca lazim disebut operasi Q<em>uery</em></p><p><strong>b. Operasi tulis (write operation).</strong></p><p>Selain operasi baca (read operation) yang berfungsi untuk membaca dan mengambil data, operasi selanjutnya yang juga berada pada basis data adalah operasi tulis. Apabila operasi baca merupakan operasi yang berfungsi mengambil data, artinya operasi ini akan mengembalikan data hasil, sebaliknya operasi tulis tidak akan mengembalikan data hasil. Hasil dari operasi tulis adalah status dari operasi (gagal atau berhasil). Apabila operasi baca merupakan operasi yang tidak membuat perubahan apapun, maka operasi tulis sebaliknya. Operasi tulis akan membuat perubahan terhadap data yang ada didalam basis data, baik itu penambahan data baru, penghapusan data yang sudah ada, perubahan sebagian nilai ataupun keseluruhan nilai yang ada pada basis data. Pada basis data, operasi tulis lazim disebut operasi <em>Command</em></p><p>Sudah kita bahas sebelumnya bahwa aplikasi atau sistem yang terhubung dengan basis data akan terlibat dengan 2 operasi baik itu operasi tulis atau operasi baca. Dikarenakan operasi tulis maupun operasi baca memerlukan sejumlah sumber daya serta waktu pemrosesan, apabila volume data serta transaksi semakin besar maka akan besar pula kinerja yang dilakukan oleh setiap operasi baca dan tulis, ini biasa disebut <em>heavy read</em> dan <em>heavy write </em>sehingga pada akhirnya akan berdampak kepada performa sistem atau aplikasi.</p><h3>Beban kerja baca (Heavy-read) versus Beban kerja tulis (Heavy-write)</h3><p>Mendesain sistem dalam menangani beban kerja baca berat (heavy-read system) versus penanganan beban kerja kerja tulis berat (heavy-write system) melibatkan strategi yang berbeda, karena setiap jenis sistem memiliki tuntutan dan tantangan unik.</p><p>Ada banyak strategi yang bisa digunakan dalam mengatasi masalah performa aplikasi atau sistem terkait basis data, sebelum kita bahas satu persatu, terlebih dahulu kita kelompokkan kedalam 2 kelompok yaitu sistem yang memerlukan beban kerja baca (heavy-read) dan yang lainnya beban kerja tulis (heavy-write).</p><p><strong>Kunci strategi dalam menangani sistem dengan beban kerja baca (Heavy-read system).</strong></p><p>Sistem yang banyak menggunakan fitur baca ditandai dengan volume operasi baca yang tinggi dibandingkan dengan operasi tulis. Skenario yang umum seperti <em>content delivery networks</em>, sistem pelaporan, atau API yang banyak menggunakan fitur baca.</p><p>beberapa kunci strategi yang bisa diterapkan sebagai berikut :</p><ol><li><strong>Caching</strong>:</li></ol><ul><li>Melakukan penerapan mekanisme caching yang ekstensif untuk mengurangi operasi pembacaan basis data. Teknologi seperti Redis atau Memcached dapat digunakan untuk menyimpan kueri atau hasil yang terbilang sering.</li><li>Caching bisa dilakukan di berbagai level (level aplikasi, level basis data, atau dengan menggunakan layanan caching khusus).</li><li>Contoh penerapan caching : Situs web berita mengalami lalu lintas tinggi dengan pengguna yang sering mengakses artikel yang sama.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tw3IipjnFjpnxbiBxSifRA.png" /><figcaption>[1]. Cache strategy (sumber : <a href="https://medium.com/@mmoshikoo/cache-strategies-996e91c80303">https://medium.com/@mmoshikoo/cache-strategies-996e91c80303</a>)</figcaption></figure><p>2. <strong>Content Delivery Network (CDN):</strong></p><ul><li>Gunakan CDN untuk menyimpan konten statis secara geografis lebih dekat ke pengguna, mengurangi latensi.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*If9ju1_UUQohWX0n_EH0OA.png" /><figcaption>[2]. (Left) Single server distribution (Right) CDN scheme of distribution (sumber : <a href="https://en.wikipedia.org/wiki/Content_delivery_network">https://en.wikipedia.org/wiki/Content_delivery_network</a>)</figcaption></figure><p>3. <strong>Load Balancing:</strong></p><ul><li>Penggunaan <em>load-balancer</em> untuk mendistribusikan transaksi baca yang masuk secara merata ke beberapa server atau replika.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pNLjknqAb4NTyu-W358ABw.png" /><figcaption>[3]. Strategi penggunaan load balancer untuk meningkatkan performa sistem.</figcaption></figure><p>4. <strong>Optimized Data Retrieval:</strong></p><ul><li>Melakukan perancangan pola akses data yang lebih efisien serta melakukan pengoptimalan kueri untuk operasi baca.</li><li>Gunakan pengindeksan data (database index) untuk mempercepat penelusuran dan pengambilan data.</li></ul><p>5. <strong>Data Partitioning:</strong></p><ul><li>Partisi data untuk mendistribusikan beban ke berbagai server atau basis data (sharding atau partisi horizontal).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*na8swaSOC-UoyNwiIC8F2Q.jpeg" /><figcaption>[4]. Konsep partitioning data pada database</figcaption></figure><p>6. <strong>Asynchronous Processing:</strong></p><ul><li>Gunakan pemrosesan asinkron untuk operasi yang tidak perlu dilakukan secara real-time.</li></ul><p><strong>Kunci strategi dalam menangani sistem dengan beban kerja tulis (Heavy-write system).</strong></p><p>Sistem yang banyak melakukan fitur penulisan data dicirikan oleh tingginya volume operasi penulisan, seperti <em>logging systems</em>, <em>real-time data collection systems</em>, atau <em>transactional databases</em>.</p><p>beberapa kunci strategi yang bisa diterapkan sebagai berikut :</p><ol><li><strong>Database Optimisation for Writes:</strong></li></ol><ul><li>Pilih database yang dioptimalkan untuk throughput penulisan tinggi (seperti database NoSQL: Cassandra, MongoDB).</li><li>Pengoptimalan skema serta indeks database untuk meningkatkan kinerja penulisan.</li></ul><p>2. <strong>Batching and Buffering:</strong></p><ul><li>Penggabungan beberapa operasi penulisan untuk mengurangi jumlah transaksi penulisan data.</li><li>contoh dari batching adalah penggunaan bulk insert dibanding dengan insert satu persatu</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/983/1*A2OPQfk4HDLWlO39pu_Ibw.png" /><figcaption>[5]. Penggunaan bulk insert pada proses tulis kedalam database.</figcaption></figure><p>3. <strong>Asynchronous Processing:</strong></p><ul><li>Menangani operasi penulisan secara asinkron memungkinkan aplikasi melanjutkan pemrosesan tanpa menunggu operasi penulisan selesai.</li></ul><p>4. <strong>Data Partitioning:</strong></p><ul><li>Partisi data untuk mendistribusikan beban ke berbagai server atau basis data (sharding atau partisi horizontal).</li></ul><p>5. <strong>Penggunaan Write-Ahead Logging (WAL)</strong></p><ul><li>Penulisan perubahan dilakukan kedalam log sebelum diterapkan secara permanen kedalam database. Proses ini bertujuan untuk memastikan integritas data serta meningkatkan kinerja penulisan.</li></ul><p>Selain dari beberapa kunci strategis yang kita bahas, ada 1 kunci lain yang bisa kita terapkan dalam mengatasi serta meningkatkan performa aplikasi atau sistem yaitu dengan penerapan CQRS.</p><p><strong>CQRS (Command — Query Responsibility Segregation)</strong></p><p>CQRS adalah singkatan dari Command Query Responsibility Segregation. Ini adalah pola yang dijelaskan oleh <a href="https://x.com/gregyoung">Greg Young</a>. Inti dari gagasan cqrs adalah penggunaan model yang berbeda antara proses tulis (memperbarui informasi) dengan model digunakan untuk baca (membaca informasi). Untuk beberapa situasi, pemisahan ini dapat bermanfaat, akan tetapi cqrs bukanlah “silver bullet” artinya solusi untuk segala situasi, karena sebagai penerapan CQRS akan menambah kompleksitas dan resiko kepada sistem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rE6IdBvV_cVTQCpIVOVEhQ.png" /><figcaption>[6]. konsep pemisahan model pada CQRS pattern (sumber : <a href="https://martinfowler.com/bliki/CQRS.html">https://martinfowler.com/bliki/CQRS.html</a>)</figcaption></figure><p>Pada CQRS, model bisa berupa logikal ataupun fisikal, secara fisikal pemisahan antara model baca dan model tulis berarti kita menggunakan database terpisah antara yang berperan dalam menulis informasi (write) ataupun yang berperan dalam membaca informasi (read). Bilamana secara fisikal database antara proses baca dan tulis terpisah, maka diperlukan mekanisme sinkronisasi sehingga perubahan data yang ditulis kedalam database X (write process) akan dapat diambil atau dibaca pada database Y pada saat proses pembacaan data (read process).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9t9XqgXyv_WJ42BeEOVxAw.png" /><figcaption>[7]. Konsep pemisahan fisikal database antara proses baca dan tulis pada CQRS pattern.</figcaption></figure><p>Ada banyak variasi yang bisa dilakukan pada CQRS pattern, misalkan proses penulisan informasi dilakukan kedalam basis data (rdbms) namun proses pembacaan data dilakukan kedalam basis data lain contoh elastic search.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*wIzTnhr6S64UwyJlfbGPcQ.png" /><figcaption>[8]. Konsep pemisahan fisikal dan tipe database pada CQRS pattern.</figcaption></figure><p>Oke, semoga penjelasan yang sudah dituliskan bisa memberikan manfaat.</p><p>Terima kasih..</p><p>Referensi :</p><p>[1]. <a href="https://martinfowler.com/bliki/CQRS.html">https://martinfowler.com/bliki/CQRS.html</a></p><p>[2]. <a href="https://medium.com/@emer.kurbegovic/cqrs-software-architecture-pattern-the-good-the-bad-and-the-ugly-efe48e8dcd14">https://medium.com/@emer.kurbegovic/cqrs-software-architecture-pattern-the-good-the-bad-and-the-ugly-efe48e8dcd14</a></p><p>[3]. <a href="https://medium.com/poatek/cqrs-with-sql-server-and-elasticsearch-1daa9e42bc64">https://medium.com/poatek/cqrs-with-sql-server-and-elasticsearch-1daa9e42bc64</a></p><p>[4]. <a href="https://medium.com/@mmoshikoo/cache-strategies-996e91c80303">https://medium.com/@mmoshikoo/cache-strategies-996e91c80303</a></p><p>[5]. <a href="https://en.wikipedia.org/wiki/Content_delivery_network">https://en.wikipedia.org/wiki/Content_delivery_network</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e00d4e3aaeb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enlarging System Design Cheat Sheet — Part 1 : SAGA and CAP theorema]]></title>
            <link>https://medium.com/@prawira.dimas.yudha/enlarging-system-design-cheat-sheet-part-1-saga-and-cap-theorema-b5340230af09?source=rss-406ade1a4a88------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5340230af09</guid>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[microservice-architecture]]></category>
            <category><![CDATA[cap-theorem]]></category>
            <category><![CDATA[saga-pattern]]></category>
            <dc:creator><![CDATA[Dimas Yudha Prawira]]></dc:creator>
            <pubDate>Mon, 29 Jul 2024 23:31:20 GMT</pubDate>
            <atom:updated>2024-07-29T23:31:20.715Z</atom:updated>
            <content:encoded><![CDATA[<h3>Enlarging System Design Cheat Sheet — Part 1 : SAGA and CAP theorema</h3><p>Sudah lama tidak menulis hal teknis mengenai dunia software engineer, kali ini saya tertarik dengan postingan dari Rajiv Ranjan mengenai System Design Cheat Sheet yang saya baca di situs profesional media LinkedIn <a href="https://www.linkedin.com/feed/update/urn:li:activity:7220974000770822144?utm_source=share&amp;utm_medium=member_desktop">https://www.linkedin.com/feed/update/urn:li:activity:7220974000770822144?utm_source=share&amp;utm_medium=member_desktop</a></p><p>Dalam postingan tersebut Rajiv Ranjan membuat dokumen slide mengenai System Design yang dirangkum dalam sebuat catatan kecil yang biasa disebut “cheat sheet”. Kenapa disebut “cheat sheet” karena catatan kecil tersebut sering kita gunakan untuk mencontek pada saat ujian :) materi yang dituliskan dirangkum sedemikian rupa sehingga hanya intisari atau poin pokoknya saja.</p><p>Oke, kita sudahi saja penjelasan tentang “cheat sheet” karena tulisan ini tidak membahas tentang cheat sheet, melainkan mengenai System Design.</p><p>Dalam System Design Cheat Sheet yang dibuat oleh Rajiv, terdapat 30 point yang beberapa diantaranya mungkin sudah kita gunakan dan beberapa yang lainnya mungkin belum. Kesemua point tersebut bisa kita gunakan untuk mendukung penyelesaian masalah pada pekerjaan kita.</p><p>30 point pada Design System Cheat Sheet sebagai berikut :</p><ol><li>Distributed transaction has to be handled</li><li>High Availability and Consistency Trade-Off</li><li>Decouple read &amp; write for high performant system</li><li>To build reliable &amp; robust system</li><li>Concurrency in distributed system</li><li>Need coordination &amp; synchronization in distributed system</li><li>Detection failure in Distributed Systems</li><li>Need ACID Compliant Database</li><li>Have unstructured data &amp; doesn’t require ACID properties</li><li>If database need to be scaled</li><li>High-Performing Database Queries Optimization</li><li>If the system has a single point of failure</li><li>For Fault-Tolerance and Durability</li><li>To distribute network traffic to get high availability, performance, &amp; throughput</li><li>Over fetching &amp; under fetching of data</li><li>For a Low Latency or ReadHeavy System</li><li>If we are dealing with a write-heavy system</li><li>High performant search and query</li><li>Static content delivery with enhanced Performance, Scalability &amp; Security</li><li>Better scalability and fault tolerance system</li><li>If need to have bulk job processing</li><li>Preventing from DOS Attacks</li><li>Centralized entry point for managing and securing API requests</li><li>Need real-time or streaming system</li><li>Bi-directional and real-time communication between a client and server</li><li>If data integrity need to be ensured</li><li>Peer-peer communication, Decentralized Data Transfer and eventual consistency</li><li>Efficient and scalable approach to data distribution in distributed systems</li><li>Handling Large Data in Network Requests</li><li>To handle traffic spikes ondemand</li></ol><p>Cukup banyak, mari kita bahas satu persatu…</p><ol><li><strong>Distributed transaction has to be handled</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GwZpo2vZJPVjLuf-cBFu8A.png" /><figcaption>[1]. Slide 1 Design System Cheat Sheet.</figcaption></figure><p>Dalam permasalahan design system khususnya pada sistem terdistribusi (distributed system), kadang kita ingin atau perlu menggunakan atau menghandle proses transaksi data yang mekanismenya juga terdistribusi (distributed transaction). Dalam proses ini kita bisa memikirkan penggunaan proses 2-phase commit (proses komit 2 fase) atau bisa juga menggunakan pola saga (saga pattern). Mari kita bahas satu persatu..</p><p><strong>a. 2-Phase Commit</strong></p><p>2-phase commit atau disingkat menjadi 2PC adalah protokol transaksi terdistribusi yang memastikan konsistensi dan integritas data di beberapa node dalam sistem terdistribusi. 2PC adalah jenis protokol commit terkecil (atom) atau disingkat ACP (Atomic Commit Protocol) yang umumnya digunakan untuk mengkoordinasikan dan menyinkronkan transaksi dalam basis data. 2PC memastikan bahwa ketika transaksi berakhir, semua perubahan pada semua sumber daya akan dikomit sepenuhnya atau dibatalkan tanpa efek samping apa pun.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/263/1*XrPs9h7YvNHHx3HOm13mSA.png" /><figcaption>[2]. Proses 2-phase commit</figcaption></figure><p>Fase-fase dalam 2-Phase Commit terdiri dari:<br><strong>1. Fase persiapan (Preparation Phase)</strong><br>Node koordinator menerima permintaan transaksi dan mengirim pesan persiapan ke semua node partisipan. Pada fase ini terdapat proses yang memastikan bahwa semua pengelola sumber daya telah menyimpan pembaruan transaksi ke penyimpanan yang stabil. Koordinator juga meminta agar semua node partisipan lainnya bersiap untuk melakukan atau membatalkan transaksi.<br><strong>2. Fase komitmen (Commit Phase)</strong><br>Pada fase ini, tergantung respon dari node partisipan, koordinator mengirim pesan <em>commit</em> atau pembatalan (abort). Semua node kemudian melakukan commit atau pembatalan (abort) pada transaksi.</p><p>2PC menstandardisasi <em>atomicity</em>, <em>consistency</em>, <em>isolation</em>, dan <em>durability </em>yang disingkat ACID dari suatu transaksi data.</p><p><strong>b. SAGA pattern</strong></p><p>Oke, solusi lainnya dalam menghandle transaksi data pada sistem terdistribusi adalah dengan penerapan pola SAGA (SAGA pattern). Lalu apa itu SAGA pattern, apakah sebuah hewan mamalia, atau hewan berkaki seribu?</p><p>Saga adalah serangkaian transaksi lokal. Setiap transaksi lokal memperbarui basis data lokal menggunakan kerangka kerja transaksi ACID yang sudah kita bahas sebelumnya. Proses transaksi selanjutnya melakukan pengiriman sebuat <em>event</em> yang digunakan untuk memicu transaksi lokal berikutnya dalam Saga. Jika transaksi lokal gagal, maka Saga akan menjalankan serangkaian transaksi kompensasi atau biasa dikenal dengan <em>rollback</em> dimana yang dilakukan pada proses ini adalah membatalkan perubahan yang telah diselesaikan oleh transaksi lokal sebelumnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WdUxE8PJ6Xzx1xlM7HDNiw.png" /><figcaption>[3]. Saga pattern</figcaption></figure><p>Saga pattern merupakan sebuah pendekatan transaksional asinkron yang pada akhirnya data yang tersimpan akan bersifat konsisten, <em>saga pattern</em> sesuai diimplementasikan pada aplikasi dengan arsitektur microservice, di mana transaksi terdistribusi dilakukan oleh serangkaian transaksi asinkron didalam setiap service.</p><p><strong>Koordinasi pada saga pattern</strong></p><p>Terdapat “dua cara” yang bisa dilakukan di dalam mengimplementasikan saga pattern, proses implementasi ini berdasarkan dari logika yang mengkoordinasikan service didalam saga. “Dua cara” tersebut adalah :</p><ol><li><strong>Saga berbasis koreografi (Choreography based)</strong></li><li><strong>Saga berbasis orkestrasi (Orchestration based)</strong></li></ol><p>Baik, mari kita bahas satu persatu..</p><p><strong>b.1. Event Koreografi</strong></p><p>Ciri khas implementasi saga pattern menggunakan koreografi event yaitu tidak adanya sistem terpusat, artinya setiap service dapat mengirimkan dan juga menerima sebuah <em>event </em>yang datang, terlepas apakah event tersebut diproses atau tidak.</p><p>Koreografi event pada saga pattern akan berakhir jika service terakhir yang terlibat dalam proses transaksi tidak melakukan pengiriman <em>event </em>apapun yang kepada service lain yang terlibat didalam saga pattern.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aefH7YIqcGyPSTFEpzHiLA.png" /><figcaption>[4]. Koreografi event</figcaption></figure><p>Pada koreografi event, proses pembatalan sebuah transaksi atau biasa disebut dengan proses <em>rollback</em> dilakukan dengan cara mengirimkan sebuah <em>event </em>yang berbeda dengan <em>event </em>yang digunakan pada proses pembuatan transaksi sebelumnya.</p><p>contoh koreografi event pada proses registrasi user wallet:</p><p>a. alur positif :</p><ol><li>CREATE_USER</li><li>CREATE_WALLET</li><li>INSERT_AMOUNT</li></ol><p>b. alur negatif (failed) :</p><ol><li>REMOVE_WALLET</li><li>REMOVE_USER</li></ol><p><strong>Keunggulan dan kekurangan koreografi event pada saga pattern</strong></p><p><strong>a. Keunggulan koreografi <em>event</em></strong></p><p><strong>Desentralisasi kontrol</strong>: Koreografi menggunakan pendekatan terdesentralisasi yaitu setiap layanan bersifat otonom (berdiri sendiri) serta bertanggung jawab terhadap apa yang dikerjakan atau diproses. Implementasi koreografi <em>event </em>dapat meningkatkan skalabilitas dan toleransi terhadap kesalahan.</p><p><strong>Tidak saling terikat (Loosely coupled)</strong> : Service yang tergabung dalam transaksi saling terkait akan tetapi tidak secara langsung, dikarenakan pada prosesnya terdapat lapisan komunikasi yang digunakan untuk mengirimkan sebuah <em>event </em>yang memisahkan antara satu service dengan service yang lain. Hal ini meningkatkan fleksibilitas, sehingga memungkinkan service untuk berkembang secara independen tanpa menyebabkan gangguan pada sistem.</p><p><strong>Selaras dengan aplikasi tipe <em>Event-Driven-Architecture</em></strong>: Implementasi koreografi event selaras dengan aplikasi tipikal Event-Driven-Architecture, yaitu setiap service dapat menerima serta bereaksi terhadap sebuah <em>event </em>dan memicu proses atau tindakan selanjutnya. Model ini sangat cocok digunakan pada sebuah sistem yang memerlukan pemrosesan dan respons <em>realtime</em>.</p><p>Sudah hukum alam bahwa setiap keunggulan akan selalu dibarengi oleh kekurangan, akan tidak adil bilamana tidak menuliskan kekurangan pada implementasi koreografi event.</p><p><strong>b. Kekurangan koreografi <em>event</em></strong></p><p><strong>Kompleksitas dalam koordinasi</strong>: Seiring dengan bertambahnya jumlah service, pengelolaan interaksi melalui koreografi dapat menjadi sangat rumit. Untuk memastikan semua service dapat menangani <em>event</em> yang relevan memerlukan perencanaan yang cermat.</p><p><strong>Tantangan pada proses <em>debugging</em> dan <em>monitoring</em></strong>: Seperti yang sudah kita ketahui bahwa koreografi <em>event</em> tidak mempunyai titik kontrol pusat sehingga proses penelusuran data serta proses diagnosis masalah dapat menjadi sulit. Proses l<em>ogging</em> dan <em>monitoring</em> yang efektif sangat penting untuk mempertahankan visibilitas ke dalam sistem.</p><p><strong>Terdapat potensi keterikatan antar service</strong>: Meskipun implementasi koreografi <em>event</em> mendorong keterikatan secara tidak langsung antar service melalui lapisan komunikasi yang menghubungkan service, akan tetapi hal tersebut tidak menutup kemungkinan masih dapat menyebabkan keterikatan langsung antara satu service dengan service yang lain bilamana proses yang dilakukan oleh satu service sangat bergantung kepada satu service yang lain walaupun dipisahkan oleh lapisan komunikasi <em>event</em>.</p><p>Selain implementasi koreografi, ada juga implementasi orkestrasi<em>.</em> Selanjutnya kita akan bahas mengenai orkestrasi.</p><p><strong>b.2. Orkestrasi <em>Event</em></strong></p><p>Salah satu hal yang jelas membedakan antara koreografi dan orkestrasi adalah bilamana koreografi tidak mempunyai kontrol artinya setiap service dapat berdiri sendiri (independent), maka orkestrasi adalah sebaliknya. Pada implementasi orkestrasi, sistem mempunyai sebuah service yang menjadi pengontrol atas service-service yang lainnya. Pada implementasi orkestrasi, orkestrator mengarahkan aliran <em>event</em>, memanggil service sesuai kebutuhan untuk mencapai proses bisnis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0NqDDR_M66PhvroV1fNVnQ.png" /><figcaption>[5]. Orkestrasi event pada saga pattern</figcaption></figure><p>Ketika terjadi masalah yang berujung pada terjadinya pembatalan transaksi, maka service yang mengalami kegagalan akan mengirimkan sebuah response <em>event </em>gagal yang selanjutnya akan diterima dan di proses oleh pusat kontrol atau orkestrator, selanjutnya orkestrator akan melakukan orkestrasi proses pembatalan kepada service-service terkait.</p><p><strong>Keunggulan dan kekurangan orkestrasi event pada saga pattern</strong></p><p><strong>a. Keunggulan orkestrasi event</strong></p><p><strong>Kontrol Terpusat</strong>: Orkestrasi menyediakan satu titik kontrol yang menyederhanakan pengelolaan interaksi. Penerapan kontrol terpusat dapat memudahkan dalam penerapan serta pengelolaan proses bisnis.</p><p><strong>Penyederhanaan penanganan kesalahan (error handling)</strong>: Dengan orkestrasi terpusat, proses penanganan kesalahan (error handling) serta proses pengembalian transaksi atau disebut proses <em>rollback</em> menjadi lebih mudah. ​​Pada implementasi orkestrasi, sebuah orkestrator dapat mengelola proses pengulangan (retry), pembatalan transaksi (rollback), serta alur proses alternatif.</p><p><strong>Peningkatan visibilitas</strong>: Implementasi orkestrasi menawarkan visibilitas yang lebih baik pada keseluruhan aliran. Orkestrator dapat mencatat dan memantau setiap langkah proses yang dilakukan sehingga memungkinkan dalam memberikan informasi mengenai status dan kinerja sistem.</p><p>Seperti halnya koreografi, orkestrasi pun mempunyai kekurangan. Kekurangan yang ada pada implementasi koreografi yaitu :</p><p><strong>Titik Kegagalan Tunggal (Single-Point of Failure)</strong>: Setiap sistem mempunyai potensi atas kegagalan atau biasa disebut <em>failure</em> atau <em>error</em>. Kontrol terpusat pada implementasi orkestrasi merupakan perbedaan, keunggulan sekaligus kekurangan, hal ini dikarenakan kontrol pusat yang menjadi pusat pengontrol proses dapat menjadi salah satu titik kegagalan (failure point). Memastikan ketersediaan (availability) serta keandalan (reliability) kontrol pusat akan sangat penting sekali untuk mencegah terjadinya pemadaman di seluruh sistem.</p><p><strong>Permasalahan Skalabilitas</strong>: Ketika skala sistem ditingkatkan, implementasi orkestrasi dapat menjadi tantangan tersendiri, dikarenakan kontrol yang terpusat setiap hambatan yang terjadi akan membatasi kinerja secara keseluruhan. Desain serta pengoptimalan yang cermat diperlukan untuk mempertahankan skalabilitas.</p><p><strong>Keterikatan antara service dengan orkestrator</strong>: Keterikatan yang terjadi antara service dengan orkestrator akan menjadi lebih kuat (tightly coupled) meskipun dipisahkan dengan lapisan komunikasi, hal ini akan mengurangi otonomi dan fleksibilitasnya. Perubahan-perubahan yang terjadi pada orkestrasi dapat memengaruhi beberapa layanan, hal ini besar kemungkinan dikarenakan diperlukannya pembaruan yang terkoordinasi didalam sistem.</p><p><strong>2. High Availability and Consistency Trade-Off</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1uk6bClCSttqH3IKmZebBQ.png" /><figcaption>[6]. Slide 2 Design System Cheat Sheet.</figcaption></figure><p>Slide kedua berbicara mengenai <em>High Availability </em>atau disingkat HA dan mengorbankan pada sisi konsistensi data. Dalam pemilihan tingkat ketersediaan yang tinggi dan mengorbankan sisi konsistensi data, kita bisa menggunakan teorema CAP, mari kita bahas satu-persatu dimulai dengan teorema CAP terlebih dahulu.</p><p>Mendesain sistem khususnya sistem terdistribusi merupakan tantangan yang menarik sekaligus berat. Hal ini memerlukan spekulasi dan dasar pemikiran yang cermat.</p><p><strong>Teorema CAP</strong> adalah salah satu pengetahuan yang harus kita miliki ketika mendesain sistem terdistribusi atau secara lebih spesifik arsitektur microservices. Teorema CAP merupakan salah satu dasar landasan berfikir (dalil) atau pernyataan dalam ilmu komputer yang menjelaskan mengenai database yang terdistribusi.</p><p>Didalam teorema CAP dijelaskan bahwa pada sistem database yang terdistribusi tidak akan memiliki lebih dari dua kondisi yang diharapkan terpenuhi dari tiga kondisi berikut, yaitu <strong>konsistensi (consistency)</strong>, <strong>ketersediaan (availability)</strong>, dan <strong>toleransi partisi (partition tolerance)</strong>. Sehingga, dari tiga properties tersebut akan didapat hanya dua kombinasi properties saja yang dapat dipenuhi. Contohnya, <strong>CA</strong> yang merupakan <strong>Consistency</strong> dan <strong>Availability</strong>, <strong>CP</strong> yang merupakan <strong>Consistency</strong> dan <strong>Partition Tolerance</strong>, dan <strong>AP</strong> yang merupakan <strong>Availability</strong> dan <strong>Partition Tolerance.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*Jl1YNSzfkL0nG4EFy484iA.png" /><figcaption>[7]. CAP theorema</figcaption></figure><p>Mari kita bahas properties dari teorema CAP satu persatu.</p><ol><li><strong>Availability</strong></li></ol><p>Ketersediaan atau dalam bahasa Inggris yaitu <em>availability adalah </em>ukuran dari kinerja sebuah sistem. <em>Availability</em> diukur menggunakan <strong><em>up-time</em></strong>. Sistem yang memiliki up time 90% akan memiliki <em>availability</em> yang lebih tinggi dari pada sistem yang memiliki <em>uptime</em> 80%. Akan tetapi pengertian availability pada teorema CAP agak berbeda sedikit. Pada teorema CAP availability mempunyai arti sebuah sistem atau semua node akan memberikan non error respon setiap waktu. Walau data tidak konsisten, apabila respon yang diberikan bukan respon galat (error), maka sistem akan dikatakan memiliki tingkat availability tinggi. Perlu diperhatikan bahwa respon ini mencakup baik itu respon pada operasi baca (read) maupun respon pada operasi tulis (write).</p><p>Tingkat availability sebuah sistem juga terkait dengan lama rentang waktu sebuah sistem memberikan respon atau dikenal dengan <em>response time </em>dalam bahasa Inggris atau bahasa teknis. Apabila <em>response time</em> sebuah sistem terlalu lama maka akan mengakibatkan klien yang mengakses sistem mengalami pengalaman yang kurang baik. Maka dari itu secara tidak langsung <em>availability </em>sistem memiliki ukuran response time yang tinggi dalam artian tidak memerlukan waktu lama dalam memberikan respon.</p><p><strong>2. Consistency</strong></p><p>Sebuah sistem database terdistribusi biasanya akan melakukan replikasi dari database ke dalam beberapa node. Konsistensi dicapai apabila kita mendapatkan semua data sama pada setiap node pada waktu yang sama. Dengan kata lain, setelah kita melakukan berbagai operasi write ke database kita akan mendapatkan data yang sama ketika melakukan operasi read pada setiap node yang kita akses.</p><p>Apabila terjadi perbedaan data maka kita menyebutkan sebagai sistem yang tidak konsisten atau<strong> <em>in consistency system</em></strong>. Perlu diperhatikan bahwa konsistensi pada teorema CAP berbeda pengertiannya dengan arti konsistensi pada sistem <strong>monolith</strong> atau pada konsep <strong>ACID database transaksional</strong>.</p><p><strong>3. Partition Tolerance</strong></p><p>Pada sistem terdistribusi, komunikasi antar node dilakukan melalui komunikasi jaringan (network) baik itu menggunakan kabel (wired) ataupun tanpa kabel (wireless). Setiap jaringan dapat mengalami kegagalan baik akibat dari permasalahan fisik ataupun <em>logical</em>. Kegagalan atau permasalahan secara fisik adalah pemasalahan yang terjadi pada perangkat keras (hardware) jaringan, contoh kabel putus. Sedangkan kegagalan atau permasalahan secara <em>logical</em> adalah permasalah yang terjadi lebih kepada perangkat lunak (software), salah satu contohnya proses garbage collection, bug pada code, dan sebagainya.</p><p>Sistem dengan partition tolerance yang tinggi adalah suatu sistem yang masih dapat bekerja walaupun komunikasi antar node mengalami gangguan. Setiap node mengetahui terjadinya masalah, dan ketika jaringan komunikasi kembali normal, data yang ada pada setiap node akan disinkronisasi ulang. Perlu diperhatikan bahwa yang dimaksud bukan node yang mati tetapi komunikasi antar node yang terganggu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yhB-oLFaEVzX3BPiYO1CZg.png" /><figcaption>[8]. Gambaran sistem database <em>up</em> akan tetapi tidak bisa berkomunikasi antar node.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PGqs_YDA2dsSsX5haiGA4A.png" /><figcaption>[9]. Gambaran jaringan komunikasi kembali normal, setiap node akan saling sinkronisasi data.</figcaption></figure><p>Partisi toleransi ini merupakan hal yang paling penting pada sistem database terdistribusi. Sesuai dengan yang sebelumnya kita bahas bahwa dalam teorema CAP kita tidak bisa memilih kesemua properties, hanya 2 kombinasi properties saja yang artinya kita tinggal memilih mana yang akan kita pertahankan dan mana yang akan kita korbankan. Apa itu konsistensi atau availability tergantung kebutuhan dari sistem yang kita rancang.</p><p><strong>Referensi :</strong></p><ul><li><a href="https://medium.com/the-legend/apa-itu-cap-theorem-839dd4a1f798">https://medium.com/the-legend/apa-itu-cap-theorem-839dd4a1f798</a></li><li><a href="https://medium.com/@siladityaghosh/choreography-vs-orchestration-in-microservices-6ff4b857cf9a">https://medium.com/@siladityaghosh/choreography-vs-orchestration-in-microservices-6ff4b857cf9a</a></li><li><a href="https://systemdesignschool.io/blog/orchestration-vs-choreography">https://systemdesignschool.io/blog/orchestration-vs-choreography</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5340230af09" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s Go tiny with tinyGo]]></title>
            <link>https://medium.com/@prawira.dimas.yudha/lets-go-tiny-with-tinygo-2ec28126bcf4?source=rss-406ade1a4a88------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ec28126bcf4</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[embedded-systems]]></category>
            <dc:creator><![CDATA[Dimas Yudha Prawira]]></dc:creator>
            <pubDate>Sat, 31 Aug 2019 22:18:27 GMT</pubDate>
            <atom:updated>2019-09-01T21:18:19.768Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r5y0NRINtyWExwg6o4crbw.png" /></figure><p>Go was designed at <a href="https://en.wikipedia.org/wiki/Google">Google</a> in 2007, the evolution of this language is tremendous. Nowadays we are almost can create any kind of application using Go, from API, tooling, game, library, and so on. So how about the embedded system or today hot term as IoT, can we use Golang for this kind of application? The answer is yes, we can.</p><blockquote><em>We never expected Go to be an embedded language and so its got serious problems…</em></blockquote><p>— Rob Pike, <a href="https://www.youtube.com/watch?v=VoS7DsT1rdM&amp;feature=youtu.be&amp;t=2799">GopherCon 2014 Opening Keynote</a></p><p>We can use Golang as the embedded language to create an application for an embedded system, the differences between embedded application and non-embedded application are :</p><ul><li>Run in an embedded board, for example, <a href="https://store.arduino.cc/nano-33-iot">Arduino Nano33 IoT</a>, <a href="https://www.adafruit.com/product/2772">Adafruit Feather M0</a>, etc…</li><li>Have very small binary sizes. So, don’t pay for what you don’t use.</li></ul><p>There is a tool, <strong>TinyGo</strong> (<a href="https://github.com/tinygo-org/tinygo">https://github.com/tinygo-org/tinygo</a>), which will be used in this article for us to compiling and flashing Go code into the microcontroller.</p><p>Let’s begin creating our first application using Go. The most common practice for creating or using a programming language for the first time and in all programming books is creating a “<strong>Hello World” </strong>program.</p><p>The “<strong>Hello world</strong>” program is considered to be the simplest kind of program that can be written. The purpose is to verify that you can write any kind of program at all. So let’s begin…</p><p>In this article, we are assuming :</p><ul><li>Go is installed and configured, if not you can follow the instructions from <a href="https://golang.org/doc/install">https://golang.org/doc/install</a> on how to install and configuring Go on your OS.</li><li>TinyGo is installed, if not you can follow the instructions from <a href="https://tinygo.org/getting-started/">https://tinygo.org/getting-started/</a> on how to install tinygo on your OS.</li></ul><p>Create a project name “hello” in “examples” namespace of our Go workspace. The project structure will be like this</p><pre>[src]<br>  |-- [examples]<br>        |-- [hello]<br>             |--- main.go</pre><h4>Our first “Hello World” program in Go.</h4><pre>package main</pre><pre>import &quot;fmt&quot;</pre><pre>func main() {<br>     fmt.Println(&quot;Hello tiny world&quot;)<br>}</pre><p>Let’s explain the code line-by-line,</p><pre>package main</pre><p>A package in the Go programming language is the way that you organize code, that is intended to be kept together and used as a single unit. We also tell Go the name of the package that the rest of our code in that file belongs to. In this case, the “main” package.</p><pre>func main()</pre><p>In the Go language, the keyword func means that the program is defining a function, which consists of one or more lines of code that will be executed one by one in order when the function is called on. We named our function “main” to tell the compiler what to start doing first when running that program.</p><pre>fmt.Println(&quot;Hello tiny world&quot;)</pre><p>We use the Println() function to output a message, on Go language it will be printed or outputted to console. But since we compile it to use on a microcontroller which it does not have one, so the output will be sent to the serial port or UART of the microcontroller.</p><h4>Compiling “Hello World” program</h4><p>Compiling “Hello World” program same as compiling another Go code, the difference here we compile the code using tinygo tool rather than using go tools</p><p>To compile the code just simply run below command</p><pre>$ tinygo build -o main.go</pre><p>The command build tell the tools that we want to compile Go code, the -o flags define the output file (if any) and the input file of Go code that wants to compile. If we do not define the output file then it will be created with the same name as the Go code, in this case, main.go.</p><p>After the compile process success, there will be an executable file created</p><pre>$ ls<br>main main.go</pre><p>If we want to compile our code using a different name, we can simply run below command</p><pre>$ tinygo build -o hello main.go</pre><p>Above command will create a file hello which is the executable file of main.go.</p><p>In the above code, we only use “fmt” Go standard library, so it’s mean we can compile the code and run under terminal. But if we use specific API in tinyGo then we can’t compile using the command above, we have to add specified target board in our compile command.</p><p>Create another file name “LED.go”</p><pre>package main </pre><pre>import ( <br>   &quot;machine&quot; <br>   &quot;time&quot;<br>) </pre><pre>// start here at main function<br>func main() { <br>   go blink(machine.LED1, 1000 * time.Millisecond) <br>   go blink(machine.LED2, 750 * time.Millisecond)<br>} </pre><pre>// blink the LED with given duration<br>func blink(led machine.Pin, delay time.Duration) { <br>    led.Configure(machine.PinConfig{Mode: machine.PinOutput}) <br>    for {  <br>       led.Low()  <br>       time.Sleep(delay)   <br>       led.High()  <br>       time.Sleep(delay) <br>    }<br>}</pre><p>The above program can be compiled and run without modification on an Arduino Uno, an Adafruit ItsyBitsy M0, or any of the supported boards that have a built-in LED, just by setting the correct TinyGo compiler target. We can also run the code on tinyGo playground as seen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MFDFEZTMf6m89jkfMG54zg.gif" /><figcaption>running go code with tinygo playground</figcaption></figure><p>The tinyGo compiler will raise an error if we not set specified target board when compiling the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gd5Ghua3-5sDqz_9BvNTmQ.gif" /><figcaption>tinygo compile error when not specified target board</figcaption></figure><p>So to compile “LED.go”, we have to add target board when executing build command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3lANJxiZ5FGDFVvzkfRK6g.gif" /><figcaption>tinygo compile success</figcaption></figure><p>But as because we have specified the target board for the compiled program, we can’t run the program anymore under terminal because executable have specified target architecture (eg : Linux, Darwin, Windows, ARM, etc..)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LZaApcm-1p9IAf_2Opbt5w.gif" /><figcaption>error run the executable file</figcaption></figure><p>To run the executable file, we have to “flash” it into microcontroller board.</p><h4>Flashing program in a microcontroller board.</h4><p>Running the program on a microcontroller, you need to compile the program for that kind of board into a binary file, and then transfer that binary file onto the microcontroller.</p><p>Before we running the program we have to make sure the board is plugged into your computer’s USB port, and if we use for example Arduino Nano33, double click the “Reset” button on the board and finally run the following command :</p><pre>tinygo flash -target arduino-nano33 ./examples/hello/LED.go</pre><p>The command tinygo flash first uses the compiler to build a temporary binary file which is the executable version of that program before it uploads to whichever microcontroller is specified as the target. The microcontroller must be connected to the computer for the compiled program to be transferred to the microcontroller board.</p><p>However, there may be slight differences to flash a specific kind of microcontroller board. See the page <a href="https://tinygo.org/microcontrollers/">https://tinygo.org/microcontrollers/</a> on the TinyGo website for details on how to flash any other kind of currently supported board.</p><p>references</p><ul><li>tinyGo website (<a href="https://tinygo.org/getting-started/">https://tinygo.org/</a>)</li><li>tinyGo github (<a href="https://github.com/tinygo-org/tinygo">https://github.com/tinygo-org/tinygo</a>)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ec28126bcf4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Streaming Golang News Channel menggunakan Apache Flume, NATS dan Telegram. (Bagian ke-3)]]></title>
            <link>https://medium.com/@prawira.dimas.yudha/streaming-golang-news-channel-menggunakan-apache-flume-nats-dan-telegram-bagian-ke-3-b97a33611ab1?source=rss-406ade1a4a88------2</link>
            <guid isPermaLink="false">https://medium.com/p/b97a33611ab1</guid>
            <category><![CDATA[apache-flume]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[nats-streaming]]></category>
            <category><![CDATA[twitter]]></category>
            <dc:creator><![CDATA[Dimas Yudha Prawira]]></dc:creator>
            <pubDate>Mon, 22 Apr 2019 12:15:27 GMT</pubDate>
            <atom:updated>2019-04-22T12:15:27.737Z</atom:updated>
            <content:encoded><![CDATA[<p>Bagian ke-3 ini merupakan lanjutan dari bagian <a href="https://medium.com/@prawira.dimas.yudha/streaming-golang-news-channel-menggunakan-apache-flume-nats-dan-telegram-bagian-ke-2-7838e579160">sebelumnya</a>, pada bagian ini kita akan membahas komponen lain yang digunakan untuk membangun Streaming Golang News Channel yaitu NATS <em>messaging system</em>.</p><h4>NATS messaging system</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2f9pC5yr2ZAmYmLwNXchUQ.png" /></figure><p><strong>Apa itu NATS?</strong></p><p>NATS adalah <em>open-source cloud-native messaging system</em>. NATS dibangun menggunakan bahasa pemrograman Go dan dikelola oleh open-source ekosistem yang bernama Synadia.</p><p>Fitur-fitur yang menarik dari NATS sebagai berikut :</p><ul><li>Highly performant (fast)</li><li>Always on and available (dial tone)</li><li>Extremely lightweight (small footprint)</li><li>Support for multiple qualities of service (including guaranteed “at-least-once” delivery with <a href="https://nats.io/documentation/streaming/nats-streaming-intro/">NATS Streaming</a>)</li><li>Support for various messaging models and use cases (flexible)</li></ul><p>NATS messaging model :</p><ul><li>Publish Subscribe</li><li>Request Reply</li><li>Queueing</li></ul><p>Mari kita pelajari satu persatu messaging model tersebut..</p><p><strong>Publish Subscribe</strong></p><p>Publish Subscribe model merupakan model komunikasi terdistribusi yang menggunakan konsep <em>one-to-many, </em>artinya publisher (pengirim) bisa mengirimkan pesan ke banyak subscriber (penerima). Publisher mengirimkan pesan kedalam sebuah subject dimana <em>subject</em> ini juga yang digunakan atau didengarkan oleh subscriber.</p><p>Konsep lain dari publish subscribe adalah alur komunikasinya hanya 1 arah saja, artinya 1 subject tidak bisa digunakan oleh subscriber dan publisher yang sama. Bilamana subscriber akan menjadi publisher (mengirimkan pesan), maka publisher harus menggunakan subject lain yang berbeda dengan subject yang digunakan untuk menerima pesan.</p><p>Pola pengiriman pesan pada publish subscribe dikenal dengan istilah QoS (Quality of Service), yaitu bagaimana pesan yang dikirim oleh publisher bisa sampai ke ke subscriber (penerima).</p><p>QoS pada NATS dibagi menjadi 2 yaitu :</p><ul><li><strong>At most once delivery</strong> : Pesan yang dikirim oleh publisher tidak dijamin akan diterima oleh subscriber, hal ini dikarenakan dasar sistem dari NATS adalah fire-and-forget. Bilamana subscriber sedang tidak aktif atau subscriber menggunakan subject yang berbeda dengan yang digunakan oleh publisher untuk mengirimkan data atau pesan, maka data atau pesan tersebut akan tidak diterima oleh subscriber.</li><li><strong>At least once delivery</strong> : Pesan yang dikirim oleh publisher akan dijamin terkirim dan diterima oleh subscriber, terlepas dari masalah jaringan atau subscriber sedang tidak aktif atau lainnya.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oxooGShrgF-v9vL48jQltw.png" /><figcaption>sumber : <a href="https://nats.io/documentation/writing_applications/concepts/#pubsub">https://nats.io/documentation/writing_applications/concepts/#pubsub</a></figcaption></figure><p><strong>Request Reply</strong></p><p>Model komunikasi lainnya adalah <em>request-reply</em>, pada NATS terdapat 2 tipe pada komunikasi <em>request-reply</em> yaitu :</p><ul><li><strong>point-to-point </strong>: 1 <em>subject</em> hanya akan digunakan untuk 1 <em>publisher</em> dan 1 <em>subscriber</em> saja.</li><li><strong>one-to-many </strong>: 1 <em>subject</em> bisa digunakan 1 <em>publisher</em> untuk mengirimkan data atau pesan ke banyak <em>subscriber</em>.</li></ul><p>perbedaan model <em>request-reply</em> terletak pada alur komunikasinya, dimana pada model <em>request-reply</em> pesan yang dikirim ke subscriber akan mengandung subject yang digunakan oleh publisher untuk menerima reply dari subscriber.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x8x362_Paoo4n-tpNiFOWQ.png" /><figcaption>sumber : <a href="https://nats.io/documentation/writing_applications/concepts/#pubsub">https://nats.io/documentation/writing_applications/concepts/#pubsub</a></figcaption></figure><p><strong>Queueing</strong></p><p>Queue atau artinya antrian adalah model komunikasi yang digunakan mengirimkan data secara berurutan (antrian) serta diproses oleh penerima juga secara berurutan. Pemrosesan secara berurutan artinya bilamana proses yang sebelumnya belum selesai maka data atau pesan lain belum akan diproses (synchronous). Tapi di NATS, model queueing bisa juga digunakan untuk melakukan workload balancing, yaitu data atau pesan akan diproses tanpa harus menunggu data atau pesan sebelumnya selesai (asynchronous).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vNdJDfAwrIYbyaJLfGaQHQ.png" /><figcaption>sumber : <a href="https://nats.io/documentation/writing_applications/concepts/#pubsub">https://nats.io/documentation/writing_applications/concepts/#pubsub</a></figcaption></figure><p>Dari model komunikasi yang sudah dijelaskan sebelumnya, maka untuk pembuatan sistem ini kita akan menggunakan model <em>asynchronous queueing</em>. Pertimbangan pemilihannya sebagai berikut :</p><ul><li>Flume sebagai <em>publisher</em> tidak memerlukan reply dari subscriber bilamana data atau pesan sudah diterima atau diproses.</li><li>Flume sebagai <em>publisher</em> melakukan pengiriman secara berurutan sesuai dengan data <em>ingest</em> Twitter.</li></ul><p><strong>Instalasi NATS server</strong></p><p>NATS repository bisa diakses pada alamat : <a href="https://github.com/nats-io">https://github.com/nats-io</a></p><p>Sementara untuk mengunduh, bisa mengakses alamat : <a href="https://nats.io/download/">https://nats.io/download/</a></p><p>Untuk melakukan pengunduhan, kita bisa menggunakan tool wget</p><pre>$wget <a href="https://github.com/nats-io/gnatsd/releases/download/v1.4.1/gnatsd-v1.4.1-linux-amd64.zip">https://github.com/nats-io/gnatsd/releases/download/v1.4.1/gnatsd-v1.4.1-linux-amd64.zip</a></pre><p>Setelah selesai proses pengunduhan, ekstrak file arsip (zip) menggunakan tools unzip</p><pre>$unzip gnatsd-v1.4.1-linux-amd64.zip</pre><p><strong>Menjalankan NATS server</strong></p><p>Masuk kedalam folder baru yang dibuat dari proses ekstraksi</p><pre>$cd gnatsd-v1.4.1-linux-amd64</pre><p>Jalankan aplikasi</p><pre>$./gnatsd</pre><p>Bilamana tidak ada masalah, maka NATS server akan berjalan dan menggunakan port 4222 (default).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EW9rnxznOWfqyQUx2noPwg.png" /><figcaption>NATS server berjalan menggunakan port default</figcaption></figure><p><strong>Test Publish dan Subscribe NATS client</strong></p><p>Selanjutnya kita akan melakukan pengetesan untuk mengirim pesan atau data ke NATS server. Sebelum itu kita coba akan melakukan tes koneksi ke port 4222.</p><p>ada beberapa cara untuk melakukan testing apakaha koneksi ke port 4222 sudah diopen atau belum, salah satu diantaranya yaitu menggunakan <em>tools</em> telnet.</p><pre>$telnet &lt;host&gt; &lt;port&gt;</pre><ul><li><strong>&lt;host&gt;</strong>, isi dengan host server NATS diinstall</li><li><strong>&lt;port&gt;</strong>, isi dengan port server NATS (default : 4222)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yKt0eheB3ruvpZJs-FKnBg.png" /><figcaption>hasil telnet ke NATS server pada port 4222 (default)</figcaption></figure><p>Untuk test publish dan subscribe ini kita akan menggunakan bahasa pemrograman Go dengan library <strong>github.com/nats-io/go-nats</strong></p><p>Code publisher.go</p><pre>package main</pre><pre>import (</pre><pre>nats &quot;github.com/nats-io/go-nats&quot;</pre><pre>&quot;log&quot;</pre><pre>)</pre><pre><br>func main() {</pre><pre>    nc, err := nats.Connect(nats.DefaultURL)<br>    if err != nil {<br>       log.Fatal(err)<br>    }</pre><pre>    defer nc.Close()</pre><pre>    if err := nc.Publish(&quot;sample_subject&quot;, []byte(&quot;this is sample message&quot;)); err != nil {<br>       log.Fatal(err)<br>    }</pre><pre>    // Make sure the message goes through before we close<br>    nc.Flush()<br>}</pre><p>Code subscriber.go</p><pre>package main</pre><pre>import (</pre><pre>    &quot;fmt&quot;<br>    &quot;log&quot;<br>    &quot;sync&quot;<br>    nats &quot;github.com/nats-io/go-nats&quot;<br>)</pre><pre>func main() {<br>   nc, err := nats.Connect(nats.DefaultURL)<br>   if err != nil {<br>      log.Fatal(&quot;failed connect to NATS server : &quot;, err)<br>   }<br>   <br>   defer nc.Close()<br>   <br>   // Use a WaitGroup to wait for a message to arrive<br>   wg := sync.WaitGroup{}<br>   wg.Add(1)<br>   <br>   // Subscribe<br>   if _, err := nc.Subscribe(&quot;sample_subject&quot;, func(m *nats.Msg) {<br>      fmt.Println(&quot;message received : &quot;, string(m.Data))<br>      wg.Done()<br>   }); err != nil {<br>      log.Fatal(err)<br>   }<br>  <br>   // Wait for a message to come in<br>   wg.Wait()<br>   <br>   // Close the connection<br>   nc.Close()<br>}</pre><p>karena kita menggunakan default QoS NATS yaitu <strong>at most once delivery</strong>, dimana pesan tidak dijamin akan diterima oleh subscriber, maka untuk ini kita harus menjalankan terlebih dahulu <strong>subscriber.go</strong> dan setelahnya baru kita menjalankan <strong>publisher.go</strong></p><p>menjalankan subscriber.go</p><pre>$go run subscriber.go</pre><p>menjalankan publisher.go</p><pre>$go run publisher.go</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2FUZKF7_4lvGKqvGkexu7Q.png" /><figcaption>hasil testing publisher dan subscriber NATS</figcaption></figure><p>Kita akan bahas lebih detail mengenai NATS pada tulisan yang lain, pada bagian ini kita akan lanjutkan ke bagian rekonfigurasi Flume agar bisa terkoneksi dengan NATS server.</p><p>Stay tunned…</p><p><em>Silahkan subscribe atau join Telegram channel </em><a href="https://t.me/golang_news_channel"><em>https://t.me/golang_news_channel</em></a><em> untuk mendapatkan informasi terbaru mengenai teknologi Go setiap minggunya.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b97a33611ab1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Streaming Golang News Channel menggunakan Apache Flume, NATS dan Telegram. (Bagian ke-2)]]></title>
            <link>https://medium.com/@prawira.dimas.yudha/streaming-golang-news-channel-menggunakan-apache-flume-nats-dan-telegram-bagian-ke-2-7838e579160?source=rss-406ade1a4a88------2</link>
            <guid isPermaLink="false">https://medium.com/p/7838e579160</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[nats-streaming]]></category>
            <category><![CDATA[apache-flume]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[twitter]]></category>
            <dc:creator><![CDATA[Dimas Yudha Prawira]]></dc:creator>
            <pubDate>Sun, 21 Apr 2019 02:29:06 GMT</pubDate>
            <atom:updated>2019-04-21T19:27:09.487Z</atom:updated>
            <content:encoded><![CDATA[<p>Pada tulisan <a href="https://medium.com/@prawira.dimas.yudha/streaming-golang-news-channel-menggunakan-apache-flume-nats-dan-telegram-bagian-ke-1-c8962b977b3b">sebelumnya</a>, kita sudah membahas gambaran umum dari sistem yang akan dibuat. Pada bagian ini, kita akan coba mempelajari komponen yang akan kita gunakan satu per-satu.</p><p>Biar tidak lupa, yuk kita lihat kembali <em>end-to-end</em> arsitekturnya.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D_TG6aPdxyU9OEixz-Zlrg.png" /><figcaption>end-to-end arsitektur</figcaption></figure><p>Komponen atau <em>tools</em> pertama yang akan kita bahas pada bagian ini adalah Apache Flume.</p><h4>Apache Flume</h4><p><strong>Apa itu Apache Flume?</strong></p><blockquote>Flume adalah aplikasi perangkat lunak yang digunakan untuk mengumpulkan, menggabungkan dan mengangkut sejumlah besar data streaming seperti file log, event, dll., dari sumber-sumber yang berbeda ke dalam tempat penyimpanan data yang terpusat.</blockquote><p>Flume adalah salah satu aplikasi perangkat lunak yang digunakan dalam dunia Big data, data-data dari sumber berbeda distream dan dimasukan kedalam tempat penyimpanan untuk selanjutnya diproses.</p><p><strong>Instalasi Apache Flume</strong></p><p>Apache Flume bisa di-unduh pada alamat berikut :</p><p><a href="https://www-us.apache.org/dist/flume/1.9.0/apache-flume-1.9.0-bin.tar.gz">https://www-us.apache.org/dist/flume/1.9.0/apache-flume-1.9.0-bin.tar.gz</a></p><p>kita menggunakan versi terbaru yaitu versi 1.9.0, untuk mengunduhnya bisa menggunakan aplikasi wget</p><pre>$wget <a href="https://www-us.apache.org/dist/flume/1.9.0/apache-flume-1.9.0-bin.tar.gz">https://www-us.apache.org/dist/flume/1.9.0/apache-flume-1.9.0-bin.tar.gz</a></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kYCPVzERsyOMo8AatP_Yug.png" /></figure><p>setelah kita mengunduh Flume, selanjutnya adalah melakukan ekstraksi file menggunakan <em>tool</em> <strong>tar</strong></p><pre>$tar -zxf <a href="https://www-us.apache.org/dist/flume/1.9.0/apache-flume-1.9.0-bin.tar.gz">apache-flume-1.9.0-bin.tar.gz</a></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_m0jBYdeOAaaFzwMVA51Zg.png" /></figure><p>Setelah proses ekstraksi selesai, maka akan ada folder baru ditempat kita melakukan proses ekstraksi. Tetapi jika kita ingin melakukan ekstraksi pada folder berbeda, maka menggunakan perintah berikut</p><pre>$tar -xf <a href="https://www-us.apache.org/dist/flume/1.9.0/apache-flume-1.9.0-bin.tar.gz">apache-flume-1.9.0-bin.tar.gz</a> -C /target/directory</pre><p>Selanjutnya masuk kedalam folder yang sudah dibuat setelah proses ekstraksi sebelumnya</p><pre>$cd apache-flume-1.9.0-bin/lib</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kw06d0QTi7Wt80Q8TgRrqg.png" /></figure><p>bisa kita lihat didalam folder lib, connector twitter sebenarnya sudah masuk kedalam distribusi Flume sehingga untuk koneksi ke Twitter, kita tidak perlu menambahkan library tambahan hanya cukup melakukan proses konfigurasi saja, akan tetapi ada kasus dimana hasil dari data ingest twitter menjadi format yang tidak bisa terbaca (unreadable). Solusi untuk masalah ini, diperlukan tambahan 1 file library (.jar) yaitu flume-sources-1.0-SNAPSHOT.jar . 1 file tambahan library bisa kita <em>build </em>dari repo berikut :</p><p><a href="https://github.com/cloudera/cdh-twitter-example">cloudera/cdh-twitter-example</a></p><p>File konfigurasi Flume berada pada folder <strong>/conf</strong>.</p><pre>$cd apache-flume-1.9.0-bin/conf</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hxhuM38WT5V10rOGfvgqyQ.png" /><figcaption>isi didalam folder konfigurasi Flume</figcaption></figure><p>didalam folder <strong>/conf </strong>terdapat beberapa file yaitu :</p><p><strong>flume-conf.properties.template</strong> : file konfigurasi connector Flume.</p><p><strong>flume-env.ps1.template</strong> : file konfigurasi environment.</p><p><strong>flume-env.sh.template</strong> : file konfigurasi environment variabel, mencakup classpath, dll.</p><p><strong>log4j.properties</strong> : file konfigurasi logging pada Flume.</p><p>Tahapan konfigurasi :</p><p>File <strong>flume-env.sh.template</strong></p><ol><li>Ubah nama file <strong>flume-env.sh.template</strong> menjadi <strong>flume-env.sh</strong></li></ol><pre>$cp flume-env.sh.template flume-env.sh</pre><p>2. Buka file flume-env.sh menggunakan teks editor (vim, vi, nano)</p><pre>$vim flume-env.sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TEMdNMP6CjfbG-k1pc1jYg.png" /><figcaption>konten file flume-env.sh</figcaption></figure><p>3. hapus tanda # pada sintak <strong>FLUME_CLASSPATH</strong> dan isi dengan path folder <strong>/lib</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jK3_v3Sm2zQ4ogPGOUj7Qw.png" /></figure><p>4. simpan hasil konfigurasi</p><p>File <strong>flume-conf.properties.template</strong></p><p>Selanjutnya kita akan melakukan konfigurasi untuk sink-source Flume. Sebagian tahapannya sama dengan tahapan konfigurasi environment Flume, hanya saja perbedaannya terletak pada konten konfigurasi.</p><ol><li>Ubah nama <strong>flume-conf.properties.template </strong>menjadi twitter-conf.properties</li></ol><pre>$cp flume-conf.properties.template twitter-conf.properties</pre><p>2. Buka file konfigurasi <strong>twitter-conf.properties </strong>menggunakan teks editor (vi, vim, nano).</p><pre>$vim twitter-conf.properties</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F4_PPkttQza2JFiBbRZGRA.png" /><figcaption>konten file twitter-conf.properties</figcaption></figure><p>3. Sesuaikan isi konfigurasi.</p><p>Berikut adalah contoh konfigurasi yang gw gunakan untuk koneksi ke Twitter dan menyimpan hasil stream ke file.</p><blockquote>catatan : kita akan menyimpan hasil stream dari twitter kedalam file terlebih dahulu sebelum selanjutnya dikoneksikan ke NATS</blockquote><pre>TwitterAgent.sources = Twitter<br>Twitter.channels = MemChannel<br>Twitter.sinks = fr1</pre><pre># Describing/Configuring the source <br>TwitterAgent.sources.Twitter.type = com.cloudera.flume.source.TwitterSource<br>TwitterAgent.sources.Twitter.channels = MemChannel<br>TwitterAgent.sources.Twitter.consumerKey = &lt;from Twitter&gt;<br>TwitterAgent.sources.Twitter.consumerSecret = &lt;from Twitter&gt;<br>TwitterAgent.sources.Twitter.accessToken = &lt;from Twitter&gt; <br>TwitterAgent.sources.Twitter.accessTokenSecret = &lt;from Twitter&gt;<br>TwitterAgent.sources.Twitter.keywords = #GoLang, #golang</pre><pre>TwitterAgent.sinks.fr1.type = file_roll<br>TwitterAgent.sinks.fr1.channel = MemChannel<br>TwitterAgent.sinks.fr1.sink.directory = ../apache-flume-1.9.0-bin/sink_dir</pre><pre># Each channel&#39;s type is defined.<br>TwitterAgent.channels.MemChannel.type = memory<br>TwitterAgent.channels.MemChannel.capacity = 10000<br>TwitterAgent.channels.MemChannel.transactionCapacity = 10000ﬁ</pre><blockquote><em>pada konfigurasi</em> <strong>TwitterAgent.sources.Twitter.type</strong>, <em>gunakan tipe</em> com.cloudera.flume.source.TwitterSource, <em>jangan gunakan tipe </em>org.apache.flume.source.twitter.TwitterSource <em>dikarenakan hasil dari ingest data akan menjadi format yang tidak terbaca.</em></blockquote><p>Untuk konfigurasi berikut</p><pre>TwitterAgent.sources.Twitter.consumerKey = &lt;from Twitter&gt;<br>TwitterAgent.sources.Twitter.consumerSecret = &lt;from Twitter&gt;<br>TwitterAgent.sources.Twitter.accessToken = &lt;from Twitter&gt; <br>TwitterAgent.sources.Twitter.accessTokenSecret = &lt;from Twitter&gt;</pre><p><em>value-</em>nya bisa kita dapatkan pada konfigurasi di sisi Twitter yang akan kita bahas selanjutnya.</p><p><strong>Twitter Application</strong></p><p>Twitter application adalah fitur dari Twitter yang ditujukan bagi pengembang pihak ketiga (third-party developer), sehingga pengembang ini bisa melakukan koneksi atau integrasi dengan Twitter.</p><p>Untuk membuat aplikasi di Twitter, silahkan akses alamat berikut : <a href="https://developer.twitter.com/">https://developer.twitter.com</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oUcs1RPZK-BZOk8VxwObeg.png" /><figcaption>halaman depan pengembang Twitter</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z77SgCw4EGA1BkECPcGjpg.png" /><figcaption>halaman aplikasi pengembang Twitter</figcaption></figure><p>Jika kita udah punya akun twitter, kita bisa login menggunakan akun tersebut dan kalo belum punya, bisa daftar terlebih dahulu.</p><p>Untuk membuat aplikasi di Twitter, klik tombol <strong>Create an app.</strong></p><p>Disini gw sebelumnya udah membuat aplikasi di Twitter dengan nama grepdata. Untuk keperluan pembuatan sistem ini, gw akan bikin aplikasi baru dengan nama <strong>GoNews.</strong></p><p>Setelah proses pembuatan aplikasi selesai, kita bisa melihat kode akses yang akan kita isi di konfigurasi Flume (token, accessToken, Keys) pada tab <strong>Keys and tokens</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y0M6FMuse1PjdqjDvTx19A.png" /><figcaption>halaman aplikasi Twitter</figcaption></figure><p>Setelah semua konfigurasi selesai dilakukan, tahapan selanjutnya adalah melakukan pengetesan dengan menjalankan Flume agent.</p><p>Untuk menjalankan Flume, masuk kedalam folder <strong>/bin</strong> lalu jalankan perintah berikut</p><pre>$./flume-ng agent --conf ../conf/ -f ../conf/twitter-conf.properties Dflume.root.logger=DEBUG,console -n TwitterAgent</pre><p>Penjelasan parameter</p><ul><li><strong>conf-file</strong> : Flume konfigurasi konektor, source, channel, sink dan <em>properti</em> yang berkaitan lainnya.</li><li><strong>name</strong> : Nama agent yang diset. dalam tulisan ini kita menggunakan nama TwitterAgent.</li><li><strong>conf</strong> : Path folder konfigurasi Flume. Umumnya, $FLUME_HOME/conf</li><li><strong>Dflume.root.logger=INFO,console</strong> : Menuliskan log aplikasi serta level yang akan ditulis kedalam log.</li></ul><p>Dikarenakan perintah tersebut menjalankan Flume di foreground proses, maka jika kita terminate atau close Flume agent akan berhenti juga. Foreground proses baik dilakukan bila kita masih dalam tahap pengetesan (trial-error) konfigurasi, tapi bilamana konfigurasi sudah tidak ada masalah, maka sebaiknya menjalankan Flume agent pada background proses sehingga <em>event </em>terminate tidak akan otomatis menghentikan Flume agent.</p><p>berikut adalah perintah untuk menjalankan Flume agent pada background.</p><pre>$nohup ./flume-ng agent --conf ../conf/ -f ../conf/twitter-conf.properties Dflume.root.logger=INFO,console -n TwitterAgent &amp;</pre><blockquote>log Flume akan dibuat otomatis pada folder yang ditentukan (telah diset pada konfigurasi <strong>log4j.properties</strong>)</blockquote><p>Jika tidak ada masalah, file stream dari Twitter akan dapat kita lihat pada file yang diset pada folder yang ditentukan</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ujmcjFNYj8M_0l8bBJbNg.png" /><figcaption>hasil ingest twitter dan sink ke file</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XyXtS7oHGtz55sZ3O0kTAA.png" /><figcaption>konten file</figcaption></figure><p>Konfigurasi Flume masih akan berlanjut ya, karena setelahnya kita akan melakukan rekonfigurasi Flume agar melakukan sink hasil stream kedalam NATS messaging server.</p><p>Stay tunned…</p><blockquote>Silahkan subscribe atau join Telegram channel <a href="https://t.me/golang_news_channel">https://t.me/golang_news_channel</a> untuk mendapatkan informasi terbaru mengenai teknologi Go setiap minggunya.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7838e579160" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Streaming Golang News Channel menggunakan Apache Flume, NATS dan Telegram. (Bagian ke-1)]]></title>
            <link>https://medium.com/@prawira.dimas.yudha/streaming-golang-news-channel-menggunakan-apache-flume-nats-dan-telegram-bagian-ke-1-c8962b977b3b?source=rss-406ade1a4a88------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8962b977b3b</guid>
            <category><![CDATA[twitter]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[telegram-messenger]]></category>
            <category><![CDATA[apache-flume]]></category>
            <category><![CDATA[nats-streaming]]></category>
            <dc:creator><![CDATA[Dimas Yudha Prawira]]></dc:creator>
            <pubDate>Fri, 19 Apr 2019 22:19:06 GMT</pubDate>
            <atom:updated>2019-04-21T02:29:31.517Z</atom:updated>
            <content:encoded><![CDATA[<p>Pada kesempatan kali ini gw mau sharing tentang pembuatan sistem streaming untuk melakukan stream berita atau informasi seputar Go atau GoLang yang didapat dari sosial media twitter.</p><p>Sebelum kita berbicara mengenai bagaimana membuat sistemnya, tidak ada salahnya kita coba mengetahui terlebih dahulu apa itu sosial media.</p><p>Sosial media adalah sebuah media untuk bersosialisasi satu sama lain dan dilakukan secara <em>online</em> yang memungkinkan manusia untuk saling berinteraksi tanpa dibatasi ruang dan waktu (<em>sumber : </em><a href="https://www.unpas.ac.id/apa-itu-sosial-media/">https://www.unpas.ac.id/apa-itu-sosial-media/</a>).</p><p>Sosial media dapat dikelompokkan menjadi beberapa bagian besar yaitu :</p><p>1. <strong>Social Networks</strong>, media sosial untuk bersosialiasi dan berinteraksi (Facebook, myspace, hi5, dan lainnya).</p><p>2. <strong>Discuss</strong>, media sosial yang memfasilitasi sekolompok orang untuk melakukan obrolan (chat) dan diskusi (GTalk, Hangout, Skype, dan lainnya).</p><p>3. <strong>Share</strong>, media sosial yang memfasilitasi sekelompok orang untuk saling berbagi file, video, music dan lainnya (youtube, slideshare, feedback, flickr dan lainnnya).</p><p>4. <strong>Publish</strong>, media sosial untuk memfasilitasi orang berbagi karya tulis (blog, digg, medium dan lainnnya).</p><p>5. <strong>Livecast</strong>, (livecastr, Podcast dan lainnya).</p><p>6. <strong>Micro blog</strong>, (twitter, plurk, pownce dan lainnya).</p><p>Pada tulisan ini gw memilih sosial media micro blog terpopuler yaitu twitter (<a href="https://twitter.com/">https://twitter.com/</a>) yang digunakan sebagai target (source) streaming informasi.</p><p><em>Tools </em>yang digunakan untuk mengambil data dari twitter pada tulisan kali ini adalah Flume (<a href="https://flume.apache.org/">https://flume.apache.org/</a>). Flume bertugas melakukan pengambilan data dari twitter dan selanjutnya akan dikirim ke message platform. Messaging platform yang akan digunakan pada tulisan ini adalah NATS (<a href="https://nats.io/">https://nats.io/</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*eP_GK8jkON0Pbd2fxUElrQ.png" /><figcaption>twitter — flume dan NATS</figcaption></figure><p>Data yang di-<em>stream</em> ke NATS selanjutnya akan di-<em>consume</em> oleh NATS <em>client. </em>NATS <em>client</em> ini adalah aplikasi berbasis Golang dan fungsi dari aplikasi ini sebagai berikut :</p><ol><li>Filtering</li><li>Reformatting</li><li>Telegram Client App</li></ol><p>Kita coba kupas satu persatu dari fungsi tersebut.</p><ol><li><strong>Filtering</strong>, data yang diambil oleh flume dari sumber (source) mungkin akan ada hasil yang tidak sesuai, fungsi dari NATS <em>client</em> ini untuk melakukan filterisasi data yang tidak sesuai berdasarkan dari tulisan, apakah ada tulisan yang mengandung “Golang” atau “Go” atau “Go programming language”, dsb. Jika tidak ada, maka data akan di drop atau diabaikan.</li><li><strong>Reformatting</strong>, data yang diambil dari NATS akan menggunakan struktur format flume, sebelum data dilanjutkan push ke Telegram channel, terlebih dahulu data tersebut akan dilakukan pem-format-an sehingga datanya menjadi data yang mudah dibaca oleh pengguna (human-readible).</li><li><strong>Telegram Client App</strong>, selain mempunyai fungsi yang sudah dijelaskan sebelumnya, aplikasi ini juga bertindak sebagai aplikasi klien <em>chat</em> platform Telegram.</li></ol><p>Dari penjelasan tersebut, maka visualisasi <em>end-to-end</em> dari arsitekturnya sebagai berikut :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D_TG6aPdxyU9OEixz-Zlrg.png" /></figure><p>Pada bagian ke-2 (<a href="https://medium.com/@prawira.dimas.yudha/streaming-golang-news-channel-menggunakan-apache-flume-nats-dan-telegram-bagian-ke-2-7838e579160">selanjutnya</a>), kita akan membahas tahapan-tahapan instalasi dan konfigurasi dari sistem ini.</p><p>Stay tunned..</p><blockquote>Silahkan subscribe atau join Telegram channel <a href="https://t.me/golang_news_channel">https://t.me/golang_news_channel</a> untuk mendapatkan informasi terbaru mengenai teknologi Go setiap minggunya.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8962b977b3b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Software Design Principle]]></title>
            <link>https://medium.com/sarccom/software-design-principle-1004d918a603?source=rss-406ade1a4a88------2</link>
            <guid isPermaLink="false">https://medium.com/p/1004d918a603</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Dimas Yudha Prawira]]></dc:creator>
            <pubDate>Mon, 25 Sep 2017 21:09:43 GMT</pubDate>
            <atom:updated>2017-09-26T23:40:04.062Z</atom:updated>
            <content:encoded><![CDATA[<p>Software Design Principle</p><p>This article was based and inspired on Software Design principle by Ahmed Adel and Go SOLID design by Dave Cheney. I will combine all those in this article, hopefully this article can be useful.</p><p>What are the principles that we should follow while we are building our software, those principles are there to help us make robust, maintainable, flexible, and scale-able software. Those principles will guide you through building your software.</p><p><strong>1- Divide and Conquer : Divide your system into small, reusable, high cohesive parts</strong></p><p>Trying to deal with big bunch of code is surely harder than dealing with small chunks, Dividing the code in small chunks will give us some benefits :</p><p>· The developers can be able to work on different parts in the system in parallel</p><p>· Smaller chunks will be easier to understand, easier to test, and easier to re-use</p><p>· Refactoring or changing a small chunk of code is way more easier and safer than doing so in a big class that is used in multiple parts of the system</p><p>· The smaller your code unit becomes, the more cohesive it is, and this respects the “Single Responsibility Principle”</p><p>· Functional programming is driven mainly by this design principle, and this can be done in Object Oriented Programming as well, for example :</p><p>In Java</p><pre><em>// a big class that should be divided :<br>// dividing the class into smaller classes based on there responsibility :</em></pre><pre>class LocationUtils {</pre><pre><em>// one responsibility is to check for location availability</em></pre><pre>   public boolean isGpsLocationEnabled(){<br>       <em>// …<br>   </em>}</pre><pre>   public boolean isNetworkLocationEnabled(){<br>       <em>// …<br>   </em>}</pre><pre><em>   // another responsibility is to get locations :</em></pre><pre>   public Location retrieveOneLocation(){<br>       <em>// …<br>   </em>}</pre><pre>   public void retrieveMultipleLocations(Consumer&lt;Location&gt; listener){<br>       <em>// …<br>       </em>listener.accept(newLocation);<br>   }<br>}</pre><pre>class OneLocationRetriever implements Callable&lt;Location&gt; {<br>       <br>       @Override<br>       public Location call() { <br>           <em>// poll one location<br>       </em>}<br>}</pre><pre>class MultipleLocationsRetriever implements   <br>          Consumer&lt;Consumer&lt;Location&gt;&gt; {<br>        <br>        @Override<br>        public void accept(Consumer&lt;Location&gt; locationListener) {<br>        <br>           <em>// listen on location<br>           </em>locationListener.accept(newLocation);<br>        }<br>}</pre><p>Callable.java and Consumer.java are Java functional interfaces, notice that after breaking down our class into separate functions (functional classes), there is no limitation on moving or re-using any of the functions, if we want to move one function to another package, nothing will be affected, further more, since all the functions implement Java functional interfaces, the users of those functions do not need to know the implementer of the java interface, like in this function :</p><pre>class MultipleLocationsRetriever implements  <br>      Consumer&lt;Consumer&lt;Location&gt;&gt; {<br> <br>      @Override<br>      public void accept(Consumer&lt;Location&gt; locationListener) { <br>           <br>             <em>// listen on location<br>             </em>locationListener.accept(newLocation);<br>      }<br>}</pre><p>The expected “<strong>locationListener” </strong>is a class of type the Consumer.java as well, so if the implementer of this interface changed or moved or even deleted, this class will not be affected.</p><p>How we do in Go</p><pre>type LocationUtils struct{}</pre><pre><em>// dividing into smaller function based on there responsibility so it will :<br>// 1. Satisfied Single Responsibility Principle<br>// 2. Smaller chunk will get easier to understand, to test the code and to re — use<br>// 3. Refactoring small chunk will be easier and safer</em></pre><pre><em>// note : public access defined by first functions letters, Uppercase defined as public while Lowercase defined as private</em></pre><pre><em>// one responsibility is to check for location availability</em></pre><pre>func (l *LocationUtils) IsGpsLocationEnabled() bool{<br>    <em>// …<br></em>}</pre><pre>func (l *LocationUtils) IsNetworkLocationEnabled() bool{<br>    <em>// …<br></em>}</pre><pre><em>// another responsibility is to get locations :</em></pre><pre>func (l *LocationUtils) RetrieveOneLocation() Location{<br>    <em>// …<br></em>}</pre><pre><em>// in Go also has a void method which not return any values :</em></pre><pre>func (l *LocationUtils) retrieveMultipleLocations(listener Consumer){<br>   listener.accept(newLocation)<br>}</pre><p>As interface in Java, Go has also interface that can be used to help us achieve loosely coupled program design. <em>Coupling</em> refers to the direct knowledge that an element of a system has of another. <em>Loose Coupling</em> means interconnecting components without assumptions bleeding through our system.</p><p>With earlier example and interface to achieve loosely coupled program design.</p><pre><em>// create interface of LocationUtils so it will achieve loosely <br>// coupled program design</em></pre><pre>type LocationHelper interface{</pre><pre><em>// just register function name, input and return value. Leave the <br>// pointer receiver</em></pre><pre>   IsGpsLocationEnabled() bool<br>   IsNetworkLocationEnabled() bool<br>   RetrieveOneLocation() Location<br>   retrieveMultipleLocations(listener Consumer)<br>}</pre><p>In Go, any value that implements those two functions satisfies the interface implicitly, i.e. there’s no implements required or anything of the like</p><p><strong>2- Cohesion : Increase Cohesion where possible</strong></p><p>We can measure the organization of the software by it’s cohesion.</p><p><strong>3- Coupling : Reduce Coupling where possible</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zwsLiI0U-59yeln8OTZXDQ.png" /></figure><p>A big software will hold many relations between it’s components, and that’s where coupling comes to play, tightly coupled system components makes it harder to re-use, maintain, and scale.</p><p><strong>4- Abstraction : Keep the level of abstraction as high as possible</strong></p><p>Make sure that our code makes it easy to hide as much details as possible. The code in previous snippet is using interface, which makes it very easy to change the implementer of those interface at any point, as long as we are dealing with interfaces, the system will be very flexible.</p><p><strong>5- Re-usability : Increase re-usability where possible</strong></p><p>Design our code so that it can be re-used in multiple contexts, we will need to follow the previous principles to be able to increase the re-usability of the code as well</p><p>Put in mind that re-usability comes at the cost of having more complexity, so we must manage the trade-off between making our code re-usable or making it simple, but if we can make it re-usable in a simple way this will be the best to do</p><p>One way to gain re-usability and reduce complexity is to divide our code into small functions and implement the known functional interfaces where possible, like the code snippets in the earlier.</p><p><strong>6- Re-use Existing : Re-use existing design and code where possible</strong></p><p>Building upon the previous principle, re-using the existing code and design benefits from the investments of the others, but put in mind that “<strong>Cloning</strong>” or “<strong>Copy/Paste</strong>” is <strong>NOT</strong> considered re-usability, you should never clone or copy/paste code, always respect the “<strong>DRY principle</strong>” (<strong>D</strong>on’t <strong>R</strong>epeat <strong>Y</strong>ourself)</p><p><strong>7- Flexibility : Increase the flexibility of your system</strong></p><p>Design your code to be prepared for future changes, we can achieve this through :</p><p>· Reduce Coupling and increase Cohesion</p><p>· Create and work with Abstractions (Interfaces)</p><p>· Never <strong>Hard-Code </strong>any thing</p><p>· Leave all options open, do not put limitations that hinders modifying the system in the future.</p><p>· Use Re-usable code, and the new code re-usable as well</p><p><strong>8- Anticipate Obsolescence / Deprecation : prepare for changes</strong></p><p>The more we use external code, the more often you will get hit with deprecated parts and soon will need to change your code to deal with the new code</p><p>· Avoid using early releases</p><p>· Avoid using libraries that are specific for particular environments.</p><p>· Avoid using undocumented libraries</p><p>· Avoid using Software from companies that will not provide long-term support</p><p>· Use standard languages and technologies that are supported by multiple vendors</p><p>“Uncle Bob” mentioned in his “<strong>Clean Architecture</strong>” that any external dependency should be outside the core of the application, they should be isolated from the business rules of the application</p><p>Also we can use some <strong>Coupling </strong>and<strong> Cohesion </strong>techniques to separate between our code and the external code, like putting the external code in a separate Layer, or putting interfaces between your code and the external code.</p><p><strong>9- Portability : Design your software to be portable</strong></p><p>Always Design our code to be portable, avoid depending on a certain OS while you are building your software. Any depending on specific configuration path will make our software less portable.</p><p><strong>10- Test-ability : Design your code to be tested by another code</strong></p><p>Unit Testing is one of the major reasons for software stability, if ew have fast and efficient test suit, a suit that wetrust with our life, we can guarantee the stability of our software, the more we divide our code, and deal with abstracts (interfaces), the more easily we can unit test every packages and supply it with fake Objects implementing the Abstract packages that it uses to do it’s Job, respecting the past rules will make unit testing our code easy to achieve</p><p>Go has come along with testing package which can be used to test our code. But keep in mind that before we test our code, the code itself must be respect SRP “Single Responsibility Principle”.</p><pre>package test</pre><pre>// Go come along with testing library that we can use to test our <br>// code. <br>import &quot;testing&quot; </pre><pre>// testing on get location //<br>func TestGetLocation(t *testing.T){<br>// we do our test case here<br>}</pre><p><strong>11- Design Defensively : Never trust how others will try to use your code</strong></p><p>Design oue code in a way that makes sure that no one will use it the wrong way, like for example, if your function is public, you should expect that some one may pass “<strong>null</strong>” to it, if it needs an object that should meet a certain criteria, you can make this function take a certain interface instead of any type, and so on</p><p>But put in mind that excessive defensive design may result in a very bad code, so you should make things as simple and clear as possible</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1004d918a603" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sarccom/software-design-principle-1004d918a603">Software Design Principle</a> was originally published in <a href="https://medium.com/sarccom">sarccom</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>