<?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 Archit Joshi on Medium]]></title>
        <description><![CDATA[Stories by Archit Joshi on Medium]]></description>
        <link>https://medium.com/@archit2693-aj?source=rss-300f56e6309------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*W5iVw47Qghywho5bpqhAIA.jpeg</url>
            <title>Stories by Archit Joshi on Medium</title>
            <link>https://medium.com/@archit2693-aj?source=rss-300f56e6309------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 15:00:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@archit2693-aj/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[Aerospike 101]]></title>
            <link>https://archit2693-aj.medium.com/aerospike-101-f85569d6a827?source=rss-300f56e6309------2</link>
            <guid isPermaLink="false">https://medium.com/p/f85569d6a827</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[nosql]]></category>
            <category><![CDATA[cache]]></category>
            <category><![CDATA[aerospike]]></category>
            <category><![CDATA[redis]]></category>
            <dc:creator><![CDATA[Archit Joshi]]></dc:creator>
            <pubDate>Mon, 22 Mar 2021 04:07:45 GMT</pubDate>
            <atom:updated>2021-03-22T04:07:45.707Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Aerospike:</h3><p>Aerospike is a distributed NoSQL database supporting the key-value store and document-oriented data models. — Providing robustness and strong consistency with no downtime. Aerospike works on a “Shared Nothing” Architecture.</p><ol><li>Scalability:- Flash and Hybrid Memory Architectures allows the aerospike database to scale Petabytes of data.</li><li>Speed:- Low Latency is maintained at a high scale (which makes a better decision in real-time).</li><li>Ease of Deployment and Management.</li><li>Low Total Cost Of Ownership:- Fueled by a hybrid memory architecture and compression, Aerospike provides significantly lower (~20%) TCO than first-generation No SQL and relational databases.</li></ol><h3>What Is “Shared Nothing” Architecture?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*vo1c9umCeqy2Uudm2uIi4Q.jpeg" /></figure><ol><li>Enables Non-disruptive Upgrades: Instead of having a certain amount of downtime while you are upgrading infrastructure with shared resources, you can upgrade a node at a time.</li><li>Eliminates Single Point of Failure: With shared systems, a single point of failure can take down your site or app entirely.</li><li>Avoids Unexpected Downtime: This allows for some amount of self-healing that can be another line of defense against unexpected downtime.</li></ol><h3>Keywords</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D2ZFW4KXYzPxtMz_bRETAQ.png" /></figure><ol><li>Namespaces: Namespaces are the top-level of the container. The namespace contains one or more Set, Records, Bins. If we compare to RDBMS, the namespace is similar to a <strong>Database</strong> Schema.</li><li>Sets: Set is more similar to a collection in MongoDB, or a <strong>table</strong> in RDBMS. It contains many records and bins.</li><li>Records: Records are more similar to <strong>rows</strong> in RDBMS. One record has one PK (key) and has one or many bins. And in one set/collection, it may have many records.</li><li>Bins: Bins in Aerospike is more similar to a <strong>column</strong> in RDBMS. We can add the index to any bin. The difference is, it’s more flexible and dynamic. It can have a lot of bins in one record. And for a single bin, it’s can store any data type ( Int, String, Byte, etc). It’s more like the column but more flexible.</li></ol><h3>Technology Behind Aerospike Database</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lO2G2fk4jv4jbO_EKPwhvw.png" /></figure><p><strong>Real-Time Transaction Engine:</strong></p><ol><li>Aerospike’s real-time engine delivers the maximum performance possible and can scale millions of transactions per second at sub-millisecond latency.</li><li>Responsible for Reading and Writing data upon request while providing consistency and isolation (which involves synchronous and asynchronous replication).</li><li>Requests to an alternate node if a node becomes unavailable as well as conflict/duplicate resolution after node rejoins the cluster.</li><li>Multiple Core System — Improves latency by reducing data across multiple regions.</li><li>Context Switch.</li><li>Data Structure Design — Safe and concurrent read, write and delete access to index tree without holding multiple locks.</li><li>Scheduling and Prioritization — In addition to key-value store operations, Aerospike supports batch queries, scans, and secondary index queries.</li><li>Memory Allocation.</li></ol><p><strong>Data Distribution:</strong></p><p>Data Partitioning that has a uniform distribution of keys in the digest space, “Avoiding the creation of hotspots during data access” — which helps in achieving high-level scale and fault tolerance.</p><ol><li>Application workload is uniformly distributed</li><li>The performance of database operations is predictable.</li></ol><p><strong>Cross-data center Replication</strong></p><p>It supports different replication topologies, including active-active, active-passive, chain, star, and multi-hop configurations.</p><ol><li>Load sharing</li><li>Remote cluster management</li><li>Data shipping</li><li>Pipe-lining</li></ol><p><strong>Storage Engine</strong></p><ol><li>It is not just the throughput and latency characteristic, but also the ability to store and process large swaths of data that defines the ability of a DBMS to scale up.</li><li>Aerospike has been designed from the ground up to leverage SSD technology. This allows Aerospike to manage dozens of terabytes of data on a single machine with sub-millisecond record access times. Aerospike supports three kinds of storage structures: Hybrid-Memory, All-Flash, and In-Memory.</li></ol><p><strong>Dynamic Data-rebalancer</strong></p><p>The data re-balancing mechanism ensures that the transaction volume is distributed evenly across all nodes and is robust in the event of node failure happening during re-balancing itself. The system is designed to be continuously available, so data re-balancing doesn’t impact cluster behavior.</p><p><strong>Smart Cluster Management (Self Healing Cluster Management)</strong></p><p>Adding and removing nodes seamlessly to the cluster.</p><ol><li>HeartBeat subsystem.</li><li>Clustering subsystem.</li><li>Exchange Subsystem.</li></ol><h3>Aerospike Client</h3><p>Aerospike provides client libraries and we use these libraries to connect to the cluster and perform operations.</p><p>Aerospike client is a first-class observer of the server, it polls and checks the state of the server every 1 sec. It knows if any new node is being added or removed and knows the partition map of each namespace which gives it an overall picture of the cluster.</p><h3>How aerospike distributes data randomly?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vZafvonqobtqn8jenIl2yQ.png" /></figure><ol><li>SetName + KeyType + UserKey is hashed to a 20 byte value using RIPEMD160 hash function.</li><li>12 bits of this hash are used as the partition id.</li><li>4096 partitions per namespace. Each namespace has its own partition map.</li><li>This hash and some additional data are stored as Primary Index in RAM.</li><li>The master and replica for a partition are decided when a cluster is formed.</li></ol><h3>What happens when a node fails?</h3><p>In an example four-node cluster, if node #3 has a hardware failure, nodes #1, #2, and #4 automatically detect the failure. Node #3 is the master for 1/4th of the data, but those partitions also exist as replicas on nodes #1, #2, and #4. These nodes automatically perform data migration to copy the replica partitions and create data masters. For example, partition 23 is replicated on node #4 and copied to node #2, which becomes the new master for partition 23. At the same time, your application (which includes the Aerospike Smart Client) becomes aware of the node #3 failure and automatically calculates the new partition map. This process occurs in reverse when a node is added to the cluster.</p><h3>Key Decisions</h3><ol><li>Persistence supported are- in Memory and Hybrid (memory + Persistence). Aerospike recommends SSD for persistent storage of data.</li><li>Each namespace (Schema) separately configured to support different persistence types.</li><li>Replication factor: depends on copies of data. Suppose replication factor: 2 means storing two copies of the data- master, and replica. Replication factor decides on nodes in cluster and data need — minimum should be 1 and maximum should be a number of nodes in the cluster.</li></ol><p><strong>Namespace configurations: Default</strong></p><pre>namespace &lt;namespace-name&gt; {</pre><pre># memory-size 4G           # 4GB of memory to be used for index and data</pre><pre># replication-factor 2     # For multiple nodes, keep 2 copies of the data</pre><pre># high-water-memory-pct 60    # Evict non-zero TTL data if capacity exceeds 60% of 4GB</pre><pre># stop-writes-pct 90       # Stop writes if capacity exceeds 90% of 4GB</pre><pre># default-ttl 0            # Writes from client that do not provide a TTL  will default to 0 or never expire</pre><pre># storage-engine memory    # Store data in memory only</pre><pre>}</pre><p><strong>Namespace configurations: Persistent Memory Storage Engine</strong></p><pre>namespace &lt;namespace-name&gt; {</pre><pre>memory-size &lt;SIZE&gt;G             # Maximum memory allocation for secondary indexes (if any).</pre><pre>storage-engine device {           # Configure the storage-engine to use</pre><pre>  # persistence. Maximum size is 2 TiB.</pre><pre>  file /opt/aerospike/&lt;filename&gt;  # Location of data file on server.</pre><pre>  filesize &lt;SIZE&gt;G                       # Max size of each file in   GiB.</pre><pre>  data-in-memory true             # Indicates that all data should   also be  in memory.</pre><pre>  }</pre><pre>}</pre><h3>Strongly Consistent (SC) and Available (AP) Modes:</h3><p>AP: The AP mode has the “eventual consistency” guarantee that a typical NoSQL database provides.</p><p>SC: To ensure that a reader gets only the latest committed value (no stale or dirty/uncommitted reads) and no committed data is lost (durable commits), Aerospike offers the SC mode that guarantees strong consistency. In this mode, a “linearizable” (explained below) read is always consistent across replicas. Aerospike’s strong consistency support has been independently confirmed through Jepsen testing.</p><p>Can be configured by using policy.</p><h3>When to Use Aerospike vs. Redis:</h3><p><strong>Need for scalability and elasticity</strong></p><p>To scale Redis, companies often add more nodes and DRAM because it’s a single-threaded system designed for in-memory processing. But DRAM is expensive, and managing increasingly large clusters isn’t easy.</p><p>Redis configuration requirements inhibit elasticity as well. Companies can only scale out a cluster by a multiple of the current number of shards, and they can’t remove shards from a cluster once they are created. So scaling up before peak periods or down afterward can be painful and expensive.</p><p>If we are building mission-critical applications where data consistency is a must, then Redis is not likely the right choice. Redis has not passed the Jepsen test for strong consistency (whereas Aerospike has). Redis supports eventual consistency, which can result in stale reads and even data loss under certain circumstances. The Jepsen framework works by firing client operations at a cluster while concurrently injecting some sort of chaos like network partitions, killing process, slowing disks, etc.</p><h3>Some challenges in Redis:</h3><ol><li>One Master, multiple Slaves — i.e. the ‘write’ throughput is limited by the one machine on which the master is running on.</li><li>Redis is single-threaded, which means there is no vertical scalability in terms of CPU.</li><li>Real-time master-slave synchronization issues — with the huge amount of writes on the master, all the changes had to be synchronized with the slaves. This can lead to slaves having to be taken offline for synchronization because of the inability to sync huge chunks of data and serve data to incoming requests from the RTB application at the same time.</li><li>There is no handy way of storing multiple different types of data in the same database — we had to store different entities in different Redis instances, having to deal with multiple connections on different ports.</li></ol><h3>How Aerospike helps:</h3><ol><li>Partitioning — it has 4096 partitions by default, which are spread across your nodes in the cluster. This helps us with the ‘write’ throughput.</li><li>Aerospike is multithreaded — makes for the most effective usage of resources.</li><li>No downtime for master-replica synchronizations — you can configure the ‘write’ policy so that the write-request is considered ‘finished’ after the replica creation confirmation.</li><li>Namespaces — all different types of data can be stored in the same cluster under different namespaces, leading to the following hierarchy: namespace &gt; set &gt; record.</li><li>SSD or in-memory storage — Aerospike has two modes: SSD versus in-memory. Redis is in-memory only, which means it becomes very costly at scale, whereas Aerospike can offer competitive performance with the use of SSDs.</li></ol><p>Thanks for reading the blog. I hope it was somewhat helpful. 😊</p><p>References: <a href="https://www.youtube.com/watch?v=PA7PGWphW8M&amp;ab_channel=Aerospike">https://www.youtube.com/watch?v=PA7PGWphW8M&amp;ab_channel=Aerospike</a></p><p><a href="https://medium.com/@me.nayan/aerospike-overview-and-setup-abc1aa110f87">https://medium.com/@me.nayan/aerospike-overview-and-setup-abc1aa110f87</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f85569d6a827" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[System Design: Incident response platform like PagerDuty.]]></title>
            <link>https://archit2693-aj.medium.com/system-design-incident-response-platform-like-pagerduty-bfe369a0dd6?source=rss-300f56e6309------2</link>
            <guid isPermaLink="false">https://medium.com/p/bfe369a0dd6</guid>
            <category><![CDATA[low-level-design]]></category>
            <dc:creator><![CDATA[Archit Joshi]]></dc:creator>
            <pubDate>Wed, 03 Mar 2021 03:42:57 GMT</pubDate>
            <atom:updated>2021-03-03T04:52:39.286Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article we will read about Low level design for a PagerDuty like, incident response and alerting platform for IT companies. Many companies use these platforms to track any incident on production and act on it based on the severity of the incident.</p><h3>1. Requirements and Goals of the System:</h3><ul><li>System should be able to identify incident reported by external systems and alert the respective on-calls.</li><li>Users should be able to configure preferred channels for notifications.</li><li>Admin should be able to generate/edit a schedule for on-call with <strong>primary</strong> and <strong>secondary</strong> on-calls.</li><li>System should have the ability to escalate the incident based on priority.</li></ul><h3>2. Entity Identification and Class definitions:</h3><p>Clearly this platform is used by set of users with some common behaviour. We can start with a base User class:</p><pre>class User {<br>  int    employeeId;<br>  String emailId;<br>  String phoneNumber;<br>  Team   team;<br>}</pre><pre>enum Team { <br>    ABC, XYZ; <br>}</pre><p>Now this base User class can be used to extend our user set to employees, managers, admin etc. For example:</p><pre>class Employee extends User {<br>  User   manager;<br>  String notificationSettings;<br>  bool   isAdmin;<br>}</pre><p>Here we are using a bitMap to represent the notification settings of a user, for example (sms, email, phone-call) can be represented as “110” which can be read as sms → ON, email → ON and phone-call → OFF.</p><p>Next we need a schedule class which will represent a schedule in our system.</p><pre>class Schedule {<br>  LocalDateTime startTime;<br>  LocalDateTime endTime;<br>  Team team;<br>  Employee primary;<br>  Employee secondary;<br>}</pre><p>Another entity in system is an incident which acts as a trigger for the alerts in the system.</p><pre>class Incident {<br>  int id;<br>  String description;<br>  Severity severity;<br>  Team team;<br>  String externalUrl;<br>  LocalDateTime startedOn;<br>  IncidentStatus status;<br>  Employee currentEscalation;<br>}</pre><pre>enum Severity { <br>    SEV1, SEV2, SEV3; <br>}</pre><pre>enum IncidentStatus { <br>    OPEN, ACKNOWLEDGED, RESOLVED; <br>}</pre><h3>3. Data structures:</h3><p>Once a schedule is created we can maintain the primary and secondary users in a <strong>circular linked-list, </strong>this will help is removing or adding new users to our on-call schedule. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7FnVwAkenxtV0qTq8esm5g.png" /></figure><p>Now if we were to create a schedule starting 1st Jan with a 7 day period. User “A” will be primary on-call in 1st week of Jan, User “B” in 2nd and so on. User “A” will again be primary after 3 weeks. Now if we were to remove/add or shift a user in the schedule we can simple change the list and our logic is not affected. For example after removing user “C” our list looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gpD24RcRILXrusvyRsqrRw.png" /></figure><h3>4. Notify():</h3><p>Before defining our notify function lets quickly discuss on how will the incidents stream to out platform. We will use <strong>Event-driven</strong> <strong>architecture </strong>to trigger and communicate between such decoupled services. Alert triggers from applications like Grafana can be pushed to a <strong>Kafka</strong> queue which will be consumed by our platform to notify().</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*fRjHXneOolkah-fZg3PbUw.png" /></figure><pre>notify(Incident incident):<br>1. fetch schedule where incident.team == schedule.team and currentTime &gt;= schedule.startTime and currentTime &lt;= schedule.endTime<br>2. fetch employee&#39;s notificationSettings where schedule.primary.id == employee.id and schedule.secondary.id == employee.id<br>3. send notification to employees with incident.description and incident.externalUrl<br>4. store the incident with IncidentStatus as OPEN, incident.currentEscalation = schedule.primary</pre><p>How will the escalation work ?<br>We will run a cron which will monitor the incident schema based on status, startedOn and severity will escalate the incident. For example if we configure <strong>SEV1</strong> to be escalated every 10 mins:</p><pre>escalateCron(Incident incident):<br>1. check if incident.startOn + 10mins &gt;= currentTime and incident.status == OPEN<br>2. fetch incident.currentEscalation employee&#39;s manager<br>3. send notification to manager with incident.description and incident.externalUrl<br>4. Update incident.currentEscalation = manager</pre><p>As an extension the system can also consume google calendar apis to fetch the leave schedule of an employee and escalation cron be enhanced to incorporate employee leaves.</p><p>Thanks for reading the blog. I hope it was somewhat helpful. 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfe369a0dd6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[System Design: Distributed Code Deployment System.]]></title>
            <link>https://archit2693-aj.medium.com/system-design-distributed-code-deployment-system-6d2b0018df50?source=rss-300f56e6309------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d2b0018df50</guid>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[high-level-design]]></category>
            <dc:creator><![CDATA[Archit Joshi]]></dc:creator>
            <pubDate>Tue, 04 Aug 2020 07:58:25 GMT</pubDate>
            <atom:updated>2020-08-05T00:23:32.180Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article I will talk about High level design for a Distributed Code Deployment System.</p><h4>1. Requirements and Goals of the System:</h4><ul><li>Global and fast code deployment system.</li><li>The system take the code. Builds the code into a binary and deploys the code globally in an efficient way.</li><li>The system be able to scale and deploy code to application servers all around the world.</li><li>Additionally we want to store the historical data of all the builds and the deployments.</li></ul><h4>2. Capacity Estimation and Constraints:</h4><ul><li>For the purpose of this problem we are assuming only 5–10 regions globally.</li><li>Each region can have upto 100K machines.</li><li>Even tough it is an internal deployment system but the system should be HIGHLY available (~99%). This is because generally a faulty deployment is followed by a rollback or roll-forward deployment hence availability matters.</li><li>The system should be extremely fast with a cap of 30 mins for the entire deployment.</li><li>Due to large codebases the binaries can take upto 10 GB space.</li><li>The system is used by large company and can have 1000 deploys/day.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xwQxJOB3o9iBP5Hk_QzhAQ.png" /></figure><h4>3. High Level System Design:</h4><p>We can think of this system to be consisting of 2 parts at a high level:</p><ol><li>Building the binary.</li><li>Deploying the binary.</li></ol><h4>Part 1: Building</h4><p>Let’s say a developer wants to deploy code corresponding to a commit SHA.<br>What seems to be a right choice is a Queuing mechanism to queue all the requests. And worker pool building the code commits in FIFO manner. <br>Workers will then store the binary in blob store (can be S3 or GCS).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*IeAa4BgGXfYQxO5PcHsUsg.png" /></figure><p>Since we want to persist the history of jobs. We can think of a SQL table for storing the job entries (this can represent our queue).<br>We define our status enum as { QUEUED, RUNNING, FAILED, COMPLETED, CANCELLED}.</p><p>How to work this as a queue ?<br>We can select the jobs where status = QUEUED and has the oldest created_at timestamp.<br>Hence the index on status and created_at will improve performance.</p><p>The fact that we have SQL database, we have ACID transactions. This enables our X number of workers to query and update the jobs as every run is a transaction and hence concurrency safe. A pseudo query would look like this:</p><pre>BEGIN:<br> SELECT * from jobs_queue where status = &quot;QUEUED&quot; <br> ORDER BY created_at ASC LIMIT 1<br> if(id == nil) ROLLBACK;<br> UPDATE jobs_queue SET status = &quot;RUNNING&quot; WHERE id = x;<br>COMMIT;</pre><p><strong>What if our worker crashes while building code ?</strong></p><ul><li>We can tackle it by adding a column last_heartbeat in our jobs_queue table. Whenever a worker picks up a job and is running it. It will continuously send heartbeat signals to the job table. Let’s say a build takes around 15 mins, the workers will send this heartbeat every 3 mins.</li><li>Now we introduce a new monitoring service that will monitor the jobs_queue table for all the “RUNNING” jobs. If we find a job’s heartbeat not updated for 2*heartbeat duration i.e. 6 mins in our case, then we rollback that job’s status to “QUEUED”.</li></ul><p><strong>How many workers are actually needed ?</strong></p><p>Assuming 5000 builds/day. And 15 mins/build → ~ 100 builds/day that a single worker will perform. Hence we can say that 5000/100 = 50 workers are required on average. We can horizontally scale the number of workers on peak hours and vice versa.</p><p><strong>Another</strong> key thing here is to update the job’s status only when the binary is successfully stored in the blob storage. As discussed we have multiple regions globally where these binaries are going to be deployed. Assuming 5 regions where we have clusters of application servers, we can have a regional blob store at each of these regions and each regional blob store serves the binary to application servers of its region.</p><p>Here we don’t want our workers to wait for this replication to be successful. We will mark the job as “COMPLETED” as soon as the binary is stored in our master blob store. The replication of the binary will happen asynchronously.</p><p><strong>What if we want the developers to be able to deploy the build only if the binary is replicated to all the regions ?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*NYhdXaHqNARWAUDsWLVxUg.png" /></figure><p>To tackle this requirement we can have a really simple service which polls the master blob store for any new binary and tracks the status of that binary by polling to all the regional blob stores.</p><p>The build is only deployable if the replication_status in the table is “COMPLETED”.</p><h4>Part 2: Deploying</h4><p>We assumed earlier that the build takes 15 mins and let’s say replication takes another 5 mins. So for us to meet the 30 min deadline for entire deployment, we are left with 10 mins. For 100K machines to download a 10 GB file from the blob store over network seems unreasonable. Hence we can create a Peer-to-Peer network. All the machines in a region are part of a Peer to Peer network, this will enable them to download multiple such binaries really fast.</p><p><strong>What exactly happens when a developer presses the “Deploy” build “Build_1” ?</strong></p><p>We can take advantage of our clustered architecture to introduce a Key-value store (like zoo-keeper, consul) at every regional cluster. And a master Key-value store which is actually updated when the developers presses the button. The idea is to have a config like -</p><pre>{<br>  build_number: &quot;build_0&quot;<br>}</pre><p>Whenever the build number in the KVS is updated the machines downloads the new binary and deploys it.<br>The regional KVS polls the master KVS for any change in the build_number and whenever the application servers are in steady state they poll their regional KVS for any change in the build_number.</p><p><strong>Let’s take a look at our final design:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mvdRRR3CgS8_HNzuqG7q9A.png" /></figure><p>Thanks for reading the blog. I hope it was somewhat helpful. 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d2b0018df50" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All about Request — Response cycle and how Go works with it.]]></title>
            <link>https://archit2693-aj.medium.com/all-about-request-response-cycle-and-how-go-works-with-it-35796792fe9b?source=rss-300f56e6309------2</link>
            <guid isPermaLink="false">https://medium.com/p/35796792fe9b</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[http-request]]></category>
            <category><![CDATA[request-response-cycle]]></category>
            <category><![CDATA[sockets]]></category>
            <dc:creator><![CDATA[Archit Joshi]]></dc:creator>
            <pubDate>Fri, 31 May 2019 16:53:20 GMT</pubDate>
            <atom:updated>2019-05-31T16:53:20.692Z</atom:updated>
            <content:encoded><![CDATA[<h3>All about Request — Response cycle and how Go works with it.</h3><p>Before diving into the core let us understand a simple yet powerful concept which serves as a solid foundation of the whole Internet, that is<strong> client/server model</strong>.</p><h3>What is Client/Server architecture ?</h3><p>Client/Server model is a computing model in which the server hosts, delivers and manages most of the resources and services to be consumed by the client. This type of architecture has one or more client computers connected to a central server over a network or internet connection.</p><p>Hmm..? Interesting, but how do they understand each other. For example requester speaks Chinese and respond-er servers in English, Hence there is a need of common protocol (some set of rules) which each have to understand to communicate efficiently.<br> Which in the case of Internet communications is <strong>HTTP.</strong></p><h3>What is a HTTP Request ?</h3><p>Whenever we want to access some files (be it HTML files of a website) on the internet we type in the URL which is nothing but the address of the file we want in the Browser. The browser then generates a sophisticated request header. Let us analyze a sample request –</p><pre>GET /requested_URL HTTP/1.1<br>Host: abs.com<br>User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0<br>Accept: text/html,application/json,application/xml;<br>Accept-Language: en-US,en;<br>Connection: keep-alive</pre><p>HTTP defines a set of <strong>request methods</strong> to indicate the desired action to be performed for a given resource. Here we use</p><ul><li>The GET method requests a representation of the specified resource. Just after the word GET we see a URI pattern which is the name of the specific route requested on the <strong>HOST</strong> i.e. <em>abs.com/requested_URL.</em></li><li><strong>HTTP/1.1 </strong>is the protocol version.</li><li><strong>User-Agent</strong> is the information of requesting web browser.</li><li><strong>Accept</strong> tells the server about the file formats that the client is expecting.</li><li><strong>Accept-Language</strong> tells the server about the languages understood by the client.</li><li><strong>Connection</strong> tells us how long should the HTTP connection should be established.</li></ul><h3>And the Response… ?</h3><p>Host checks for more information to process the request like headers values, the method GET, POST, PUT etc.Response sent by a server consists of a <strong>Header</strong> and a <strong>Body.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Sa6cgRhR2CsnBsqo" /></figure><p>The response is then rendered by the requesting browser according to the<em> </em><strong><em>Content-type</em></strong><em> </em>field in the response header.</p><h3>What is 200 OK ?</h3><p>The first line is called the status line. It supplies the HTTP version, status code and status message. The status code informs the client of the status of the HTTP server’s response. In HTTP/1.1, 5 kinds of status codes were defined:</p><pre>- 1xx Informational<br>- 2xx Success<br>- 3xx Redirection<br>- 4xx Client Error<br>- 5xx Server Error</pre><p>Status codes are <strong>short way</strong> of server to tell client what’s the result of the request. We all have seen <strong>404 : File not found</strong> and now we know what it is.</p><h3>So what did we understand so far..?</h3><blockquote><strong><em>The request-response cycle begins with a client sending a request message to a server. The server handles the request and sends a response message back to the client. An HTTP message has a header and sometimes a body. The header contains meta-information about the message. The body contains the content.</em></strong></blockquote><h3>How Go works with web ?</h3><p>We’ve discussed that web applications are based on the HTTP protocol, and Go provides full HTTP support in the net/http package. Let us first look into the http package working mechanism –</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lVkTq-NTQxvYZOxF" /></figure><p><strong>Understanding the Workflow :</strong></p><ol><li><strong>Create a listening socket, listen to a port and wait for clients.</strong><em>OK. But what is a socket ?</em><br> A <strong>socket</strong> is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent to.</li><li><strong>Accept requests from clients.</strong><em>And…how exactly all this is happening ?</em><br> The client knows the host name of the machine on which the server is running and the port number on which the server is listening.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/0*f6MbGMYMJAF8FcGj" /></figure><ol><li>The client also needs to identify itself to the server so it binds to a local port number that it will use during this connection. If everything goes well, the server accepts the connection.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/0*WtN_6gZcXRMrVUcE" /></figure><ol><li>The client and server can now communicate by writing to or reading from their sockets.</li><li><strong>Handle requests, read HTTP header.</strong> If the request uses POST method, read data in the message body and pass them to handlers. Finally, socket returns response data to clients.</li></ol><h3>How does it maps to the real code ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*41RnGH9tSO4eT9Jl" /></figure><p>Go uses ListenAndServe to handle the steps:</p><ul><li>Initialize a server object.</li><li>Call net.Listen(&quot;tcp&quot;, addr) to setup a TCP listener and</li><li>Listen to a specific address and port.</li></ul><p>We can see that srv.Serve(net.Listener) is called to handle client requests. In the body of the function there is a for{}. It accepts a request, creates a new connection then starts a new <strong>goroutine</strong>, passing the request data to the go c.serve() goroutine. This is how Go supports high concurrency, and every goroutine is independent.<br> A <strong>goroutine</strong> is a lightweight thread managed by the Go runtime, to learn more about go routine follow :<strong> </strong><a href="https://ritiktechblog.wordpress.com/2018/05/28/concurrency-in-go-goroutines-and-channels/"><strong>Concurrency in GO.</strong></a><br> conn parses request c.ReadRequest() at first, then gets the corresponding handler: which is the second argument we passed when we called ListenAndServe. Because we passed nil, Go uses its default handler handler = DefaultServeMux.</p><p><strong>So what is DefaultServeMux ?</strong><br> Its the router variable which can call handler functions for specific URLs. For example http.HandleFunc(&quot;/&quot;, methodName). We’re using this function to register the router rule for the “/” path. When the URL is /, the router calls the function methodName. DefaultServeMux calls ServerHTTP to get handler functions for different paths, calling methodNamein this specific case.<br> Finally, the server writes data and responds to clients.</p><p>Here is a sample code to get you started and sum-up all the things discussed above:</p><pre>package main<br>import (<br>   &quot;fmt&quot;<br>   &quot;net/http&quot;<br>)</pre><pre>func functionHandle(w http.ResponseWriter, r *http.Request) {<br>   fmt.Println(&quot;Worked !&quot;)<br>}</pre><pre>func main() {<br>   http.HandleFunc(&quot;/&quot;, functionHandle)<br>   http.ListenAndServe(&quot;:8080&quot;, nil)<br>}</pre><p>Running the code by “go run &lt;filename&gt;” will initialize a server listening at port 8080.</p><p>Hope now you have a better understanding of how things work on the <strong>Internet </strong>and how Golang’s simplicity helps in creating a simple web server. There is much more to web development via Golang but this is all to get your basics right and give you a head-start in the <strong>world of GO</strong> !<br> <em>Happy coding :)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35796792fe9b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Object Oriented Programming and Ruby]]></title>
            <link>https://archit2693-aj.medium.com/object-oriented-programming-and-ruby-45bea439027f?source=rss-300f56e6309------2</link>
            <guid isPermaLink="false">https://medium.com/p/45bea439027f</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[oops-concepts]]></category>
            <dc:creator><![CDATA[Archit Joshi]]></dc:creator>
            <pubDate>Fri, 31 May 2019 16:44:57 GMT</pubDate>
            <atom:updated>2019-05-31T16:44:57.407Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Object Oriented Programming ?</h3><p>Object oriented programming is the way of looking the real world as a world full of objects with some definite shape, size and behavior. It is based on a model where we create objects and perform actions on them. This is done by sectioning off code to do small useful actions which we call “methods”.</p><h3>Object</h3><p>The word object is precisely a reference to a real word entity or at least a abstract representation of something that can be treated as an object. Be it ship or a simple thing like a bottle. Object in Object Oriented Programming has two basic properties, data and behavior.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V9MTphKvLV4htmAS" /></figure><h3>Class</h3><p>A class is the actual definition of an object or we can say a blueprint of an object. Class can be treated as a tool from which we can produce objects of a kind. For example once a blueprint of a car(the design of the car) is created, N number of identical cars can be created with different colors, or day different types of tires but the core is same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*6xEWRvGkaTILGVqU" /></figure><p>We can demonstrate classes and objects with an easy <strong>ruby </strong>example :</p><pre>class Car<br> def initialize(car)<br>   @model_name = car[:model_name]<br>   @car_class = car[:car_class]<br>   @acceleration = car[:acceleration]<br>   @top_speed = car[:top_speed]<br>   @color = car[:color]<br> end</pre><pre> def change_car_color(new_color)<br>   @color = new_color<br> end<br> <br> def info<br>   puts &quot;The model #{@model_name} is a #{@car_class} class car with an acceleration of #{@acceleration} and #{@top_speed} top speed&quot;<br> end<br>end</pre><p>We can create an object of this class :</p><pre>car_object = Car.new({model_name: &quot;911 Turbo&quot;, <br>                      car_class: &quot;Sports&quot;, <br>                      acceleration: &quot;0 to 60 is 5.2 seconds&quot;, <br>                      top_speed: &quot;205 kmph&quot;,<br>                      color: &quot;Yellow&quot;<br>                     })<br>car_object.info</pre><p>The line <em>car_object.info </em>invokes the method info on the newly created object and displays the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PBFVyKxD60-7KGQa" /></figure><p>Note that we have used ruby’s standard terminology of declaring instance variables by using @, for example : <strong><em>@top_speed</em></strong></p><p>We have two types of variables which we generally use in classes<br> 1. Class variables.<br> 2. Instance variables.<br> The issue with class variables is inheritance. So let us look at the concepts of <strong>Inheritance</strong> first to understand the underlying issue.</p><h3>Inheritance</h3><p>Suppose we want certain common behavior to be available to certain objects. For example a <strong>class Vehicle</strong> can have some common characteristics of all the vehicles such as number_of_wheels or seating_capacity, which <strong>class Car</strong> and a <strong>class Bike </strong>also needs so by inheriting these common properties from Vehicle class will allow us to reuse our code and later if a new <strong>class Bus</strong> has to be introduced then it can simply inherit vehicle and enjoy its properties.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aLIZRkV5zwLhxuXQ" /></figure><h3>Class variables vs Instance Variables</h3><p>Now coming back to the difference between class and instance variables, lets us take an example.</p><pre>class Vehicle<br>  @@number_of_wheels = 4<br>  def self.number_of_wheels<br>    @@number_of_wheels<br>  end<br>end</pre><p>and another class Bike which inherits the class Vehicle</p><pre>class Bike &lt; Vehicle<br>   @@number_of_wheels = 2<br>end</pre><p>Now if we do</p><pre>puts Bike.number_of_wheels        <strong><em>#==&gt; 2</em></strong><br>puts Vehicle.number_of_wheels     <strong><em>#==&gt; 2</em></strong></pre><p>It happened because when you set a class variable, you set it for the super class and all of the sub classes. The instance variables are for the instance of a class i.e. every object carries its own copy of instance variables defined it the class.</p><p>Hope you liked the basic introduction to the Object oriented programming with ruby. More features of the Object oriented programming such as Encapsulation, Polymorphism, Abstraction are yet to explored.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45bea439027f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>