<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Arnab Sen</title>
    <description>The latest articles on DEV Community by Arnab Sen (@arnabsen1729).</description>
    <link>https://dev.to/arnabsen1729</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F440483%2F702e7cc8-90b6-485e-b2e3-696227b07eb5.png</url>
      <title>DEV Community: Arnab Sen</title>
      <link>https://dev.to/arnabsen1729</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arnabsen1729"/>
    <language>en</language>
    <item>
      <title>Row, Row, Raft Your Nodes: A Guide to Consensus in Distributed Systems</title>
      <dc:creator>Arnab Sen</dc:creator>
      <pubDate>Sun, 22 Oct 2023 18:05:23 +0000</pubDate>
      <link>https://dev.to/arnabsen1729/row-row-raft-your-nodes-a-guide-to-consensus-in-distributed-systems-144c</link>
      <guid>https://dev.to/arnabsen1729/row-row-raft-your-nodes-a-guide-to-consensus-in-distributed-systems-144c</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;I have been recently diving into the world of Distributed systems and I came across a rather interesting paper: &lt;a href="https://raft.github.io/raft.pdf"&gt;&lt;em&gt;"In Search of an Understandable Consensus Algorithm"&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt; What caught my attention was the paper's primary objective of creating a consensus algorithm that is &lt;strong&gt;easy to understand&lt;/strong&gt;. Typically, in the realm of new research, we tend to emphasize factors like efficiency, correctness, and conciseness while overlooking how accessible a concept is for others to grasp and apply in practical scenarios.&lt;/p&gt;

&lt;p&gt;We often neglect how easy it for someone is to grasp the concept and use it to build practical stuff or solve real problems. Sometimes we do the opposite, if something works but is very hard to understand and is confusing we consider it to be very "clever" and end up rewarding complexity. That's why I appreciate the approach taken by the authors, Diego Ongaro and John Ousterhout, in prioritizing the algorithm's comprehensibility.&lt;/p&gt;

&lt;p&gt;With many major corporations transitioning to distributed systems, having an algorithm that is both easy to understand and intuitive can empower developers to create systems more seamlessly and devise more efficient implementations."&lt;/p&gt;

&lt;h1&gt;
  
  
  So, what is Consensus
&lt;/h1&gt;

&lt;p&gt;Let's start with a simple analogy:&lt;/p&gt;

&lt;p&gt;You have been invited to a party and you have dressed up all nice and good. Then you ask your 4 friends if you are looking good (if you don't have so many friends just imagine you do, at this point, you must be good at it). Two of them say that you are looking good, and the rest say you are not. What are you supposed to do?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--g3dHN3PX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1697975592643/8d8e522a-d77b-4b86-9fda-04b0ccb1b633.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--g3dHN3PX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1697975592643/8d8e522a-d77b-4b86-9fda-04b0ccb1b633.png" alt="" width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But if 3 of them said that you do look good (quite unusual right?) then you can go with the majority decision.&lt;/p&gt;

&lt;p&gt;This is consensus !!&lt;/p&gt;

&lt;p&gt;In distributed systems, we know that we have multiple nodes, and consensus refers to coming to an agreement.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Consensus simply means to get all the nodes in distributed computing to agree on a common value or decision, despite the presence of faults, delays, or unreliable communication. This agreement is crucial for ensuring that the distributed system functions correctly and consistently.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Even though it sounds simple, many broken systems have been built in the mistaken belief that this problem is easy to solve.&lt;/p&gt;

&lt;p&gt;There is a pattern in most of the fault-tolerant systems. For example, in MapReduce, the computation is replicated but the whole thing is controlled by a single master. Similarly, we have GFS which replicates the data and has a single master to determine who the primary is for the piece of data. The benefit of having such a single master system is that there will be no disagreement. But at the same time, it makes it a single point of failure. So we need some sort of consensus to avoid such failures.&lt;/p&gt;

&lt;p&gt;💡&lt;/p&gt;

&lt;p&gt;It's fine if you don't have an understanding of MapReduce or GFS, they were just examples. You can read my blog on MapReduce&lt;/p&gt;

&lt;p&gt;&lt;a href="https://arnabsen.dev/understanding-mapreduce"&gt;https://arnabsen.dev/understanding-mapreduce&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  History of Consensus Protocols
&lt;/h1&gt;

&lt;p&gt;Well, now that I think "history" is an overstatement cause there is just one very popular protocol called "Paxos" which has been the gold standard for a long long time. First submitted in 1989 by &lt;strong&gt;the Leslie Lamport&lt;/strong&gt; , the Paxos protocol is named after a fictional legislative consensus system on the island of Paxos in Greece.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3JXfC_gG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://charlesxu.io/assets/images/sys-design/cover.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3JXfC_gG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://charlesxu.io/assets/images/sys-design/cover.jpg" alt="System Design Interview: Scaling Single Server" width="704" height="580"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;FYI Leslie Lamport was the creator of LaTeX. He also won the Turing Award which is like the Nobel Prize for Computer Science.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://youtu.be/rkZzg7Vowao"&gt;https://youtu.be/rkZzg7Vowao&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The problem with Paxos was it was really hard to wrap our minds around. It only solved a portion of the problem and hence made it difficult to build systems around Paxos.&lt;/p&gt;

&lt;h1&gt;
  
  
  Raft Algorithm
&lt;/h1&gt;

&lt;p&gt;As mentioned before the authors' primary design goal when building Raft was "understandability".&lt;/p&gt;

&lt;p&gt;🤓&lt;/p&gt;

&lt;p&gt;Even the author of Raft found it difficult to understand Paxos and he once said that it took him building a new consensus algorithm to really understand how Paxos worked and its correctness.&lt;/p&gt;

&lt;p&gt;Now this doesn't mean that Raft is very very easy to understand, there are still a lot of intricacies and edge cases to cover, but I will try my best to give a brief overview of the entire thing. So let's start.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are we dealing with?
&lt;/h2&gt;

&lt;p&gt;We have a client, which can be a user or a service etc. And it tries to fetch some data from the server we have which is nothing but a cluster of nodes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--b9EVu7Re--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1697979457327/2dee5b50-4dc0-4198-b872-d0703b805528.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--b9EVu7Re--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1697979457327/2dee5b50-4dc0-4198-b872-d0703b805528.png" alt="" width="800" height="518"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, to ensure consensus we need the nodes to agree on a particular value and then send that to the client.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do we ensure that all the nodes have the same value?&lt;/strong&gt; Raft achieves that through something called a &lt;strong&gt;"Replicated Log".&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It ensures that all the commands (or operations) that need to be performed are replicated across the nodes in the same order. So, let's say you have a variable &lt;code&gt;X&lt;/code&gt; initially, the value is &lt;code&gt;0&lt;/code&gt; and then you perform some operations like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;add 5&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;mul 10&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;sub 15&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If these commands were logged in the same order then the final value of &lt;code&gt;X&lt;/code&gt; will be the same for all the nodes assuming the fact that the operations in the nodes (which are also referred to as state machines) are deterministic.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PtJOhJ4j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1697981500138/7195a039-5805-4547-a346-4a590fb4781c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PtJOhJ4j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1697981500138/7195a039-5805-4547-a346-4a590fb4781c.png" alt="" width="709" height="532"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, when a new command gets proposed, it first gets logged on all the nodes (at least most of the nodes) at the end of their logs. Only when the log gets properly replicated, does the node perform its computation and send the result to the original client.&lt;/p&gt;

&lt;p&gt;The idea behind this is if the logs get replicated properly the cluster can continue functioning as long as the majority of the nodes are up (Yes, it's more like democracy, the majority wins).&lt;/p&gt;

&lt;h2&gt;
  
  
  Who will instruct the nodes on what to do?
&lt;/h2&gt;

&lt;p&gt;Again similar to democracy, here also we have a leader node elected by other nodes. The leader node is responsible for talking to the client, giving commands to the other nodes, etc.&lt;/p&gt;

&lt;p&gt;Before diving deep into the functioning of the leader let's see how the nodes become a leader.&lt;/p&gt;

&lt;h3&gt;
  
  
  Server States
&lt;/h3&gt;

&lt;p&gt;The nodes/server have 3 states:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Follower&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Candidate&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Leader&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In normal service, there will be just one Leader and all the other servers will be Followers.&lt;/p&gt;

&lt;p&gt;Followers are passive, they issue no requests and can only respond to requests from Leaders and Candidates.&lt;/p&gt;

&lt;p&gt;The Leader handles all the client requests. It also sends regular heartbeats (empty requests) to the Followers to maintain authority. &lt;em&gt;More like it's saying "Don't get too excited, I am still your leader".&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If a Follower receives no communication over a time period (called &lt;strong&gt;election timeout&lt;/strong&gt; ) it assumes that no Leader is available and starts the process of &lt;strong&gt;Leader Election&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Leader Election
&lt;/h3&gt;

&lt;p&gt;Let's talk about &lt;strong&gt;term&lt;/strong&gt; before diving into Leader Election. To have consensus we need to have a mechanism to detect obsolete information. Like if a particular server was a leader and then it stopped responding, and a new leader was appointed. We need to ensure that the other servers don't take instructions from the old leader anymore. Raft achieves this by dividing the time into terms or arbitrary lengths called &lt;strong&gt;term.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HXBWVzdf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1697989611948/05a6e6a7-ed55-498b-8a50-7081d31c6c71.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HXBWVzdf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1697989611948/05a6e6a7-ed55-498b-8a50-7081d31c6c71.png" alt="" width="435" height="185"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each term starts with an election of the leader and then if the election is successful the leader rules for some period of time which is represented in green in the above diagram.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can see how this is similar to the administrative process of a country where each leader has a term like 5 years and then post that election happens to elect a new leader.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In Raft, now the interesting thing is there is no global concept of &lt;strong&gt;term&lt;/strong&gt; among the servers. Each server starts with its own terms.&lt;/p&gt;

&lt;p&gt;When the election process starts the follower increments its current term index and becomes a candidate. It votes itself and then sends specific requests to the other nodes requesting to be a leader in other words asking for their vote. This happens by a special kind of request called &lt;code&gt;RequestVote RPCs&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Whenever the server communicates with the other it includes what it thinks the current term index is. Then the other server responds by including its term index.&lt;/p&gt;

&lt;p&gt;Now if there is a mismatch the server with the lower-term starts having an identity crisis and falls back to being a follower. And the other server just ignores it.&lt;/p&gt;

&lt;p&gt;A Server is entitled to vote only one server and that happens on a first come first serve basis. So by the end of the process, the Candidate server with the most votes becomes the leader and then sends heartbeat messages to all of the other servers to establish its authority and prevent new elections.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_gSPT986--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1697991199037/c1093f81-f805-45d0-b9d3-027985d3dd1b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_gSPT986--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1697991199037/c1093f81-f805-45d0-b9d3-027985d3dd1b.png" alt="" width="572" height="372"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here I had a doubt, what if all the server realizes that the leader no longer exists or the current term is over, votes themselves, and requests a vote at the same time? They will just end up waiting indefinitely to get majority votes. Or what if two candidates receive the same number of votes (this is called a split vote)?&lt;/p&gt;

&lt;p&gt;Raft solves this by using randomized election timeouts, which means election timeouts are chosen randomly from a fixed interval (e.g., 150-300 ms). This way in most cases only one server will timeout at a time, become a candidate, and will request a vote before the other server times out. Even in case of a split vote, each candidate restarts its randomized election timeout at the start of an election and it waits for that timeout to elapse before starting the next election. This randomness drastically reduces the chances of another split vote.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yFdvYBHL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1697991568136/26dbcb95-8cd0-4355-8644-cae2ed4a7ace.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yFdvYBHL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1697991568136/26dbcb95-8cd0-4355-8644-cae2ed4a7ace.png" alt="" width="725" height="905"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How does the normal operation happen?
&lt;/h2&gt;

&lt;p&gt;Let's go through how a normal operation will take place with consensus in Raft.&lt;/p&gt;

&lt;p&gt;First, the client sends a command to the leader. Wait, how will the client know who the leader is? Well, the client can send it to any server and if the server is a follower it will simply redirect it to the leader.&lt;/p&gt;

&lt;p&gt;The Leader appends the command to its log and sends another request (called &lt;code&gt;AppendEntries RPC&lt;/code&gt; request to all its followers). The followers on receiving this request just append the new log to their existing logs record. Note, at this point they just append it and don't actually perform any computation. It's the leader who decides when it is safe to apply the log entry i.e. when the entry has to be committed. This is actually called 2PC (Two Phase Commit).&lt;/p&gt;

&lt;p&gt;The append request contains two identifiers, one is the term index which I already mentioned before, and another is the log index which is the position of the new entry in the log. The leaders use these two index values to determine if the majority of the servers have the logs up to date and then issue a commit.&lt;/p&gt;

&lt;p&gt;In any case, the logs become inconsistent, the leader forces the followers to duplicate the leader's log. To bring a followers log into consistency with its own, the leader finds the latest log entry where the two logs agree, deletes any entries in the followers log after that point, and sends the follower all of the leaders entries after that point.&lt;/p&gt;

&lt;p&gt;This is how the Leader ensures that every server (or at least the majority) has the same order of the logs i.e. consensus is reached, performs the computation, and then responds to the client.&lt;/p&gt;

&lt;p&gt;This is how we can build a system with high data consistency with Raft and many distributed consistent database like CockroachDB uses Raft.&lt;/p&gt;




&lt;p&gt;This was a very brief overview of Raft. There are many more aspects to this that couldn't be covered in a blog and I urge you to go through the original paper. I hope you found my blog useful. If you have any feedback share it in the comments. You can sign up for the Hashnode newsletter to get notified every time I post a blog. Learn more about me at &lt;a href="https://dev.to/arnabsen1729/-whoami-56nh-temp-slug-8931258"&gt;arnabsen.dev/about&lt;/a&gt;. Have a nice day.&lt;/p&gt;

</description>
      <category>distributedsystems</category>
      <category>tutorial</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>Understanding MapReduce</title>
      <dc:creator>Arnab Sen</dc:creator>
      <pubDate>Sat, 30 Sep 2023 07:25:48 +0000</pubDate>
      <link>https://dev.to/arnabsen1729/understanding-mapreduce-16al</link>
      <guid>https://dev.to/arnabsen1729/understanding-mapreduce-16al</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;MapReduce is a programming paradigm that helps us perform large-scale computation across computing clusters.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;DISCLAIMER:&lt;/strong&gt; In this blog, I will take a very simple overview of this topic. If this blog actually spikes your interest and you want to delve into the technical nitty-gritty then I would urge you to read the original paper: &lt;a href="https://static.googleusercontent.com/media/research.google.com/en//archive/mapreduce-osdi04.pdf"&gt;&lt;strong&gt;"MapReduce: Simplified Data Processing on Large Clusters"&lt;/strong&gt;&lt;/a&gt; (It was written by the Top-Gs in the programming world: &lt;a href="https://www.informatika.bg/jeffdean"&gt;Jeff Dean&lt;/a&gt; and Sanjay).&lt;/p&gt;

&lt;h1&gt;
  
  
  Background
&lt;/h1&gt;

&lt;p&gt;Let's start with a little bit of background.&lt;/p&gt;

&lt;p&gt;Currently at Google, I am working on a project that requires me to process a large amount of logs, perform some computations, and then write the computed results in a database. This has to happen on a daily basis and the output is then consumed by downstream teams for further operation.&lt;/p&gt;

&lt;p&gt;One might think, what's the big deal in that? Just take the log file as input, implement the logic, and write the results to an output file. That's what we have always been doing.&lt;/p&gt;

&lt;p&gt;Well, one thing we should take into consideration is the size of the file that we are dealing with. It is actually in the multiple of Terabytes. Taking our traditional path for problems like this would cause a lot of issues like:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Performance Issue:&lt;/strong&gt; the entire thing would probably take a whole lot of time and it can have a lot of potential bottlenecks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Memory Issue:&lt;/strong&gt; How are we even going to load the entire TBs of data into memory? We have to implement some partitioning ourselves to do it effectively.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability Issue:&lt;/strong&gt; Very difficult to actually scale it to multiple machines.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fault Tolerance:&lt;/strong&gt; Let's say you somehow managed to overcome all the problems above, what if at the last moment, something crashes, how are we going to recover?&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is why Google came up with the MapReduce paradigm. There is also an open-source implementation of the same called &lt;strong&gt;"Apache Hadoop"&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C0elEKu---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://hadoop.apache.org/hadoop-logo.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C0elEKu---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://hadoop.apache.org/hadoop-logo.jpg" alt="hadoop-logo" width="281" height="71"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://github.com/apache/hadoop"&gt;https://github.com/apache/hadoop&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What's MapReduce?
&lt;/h1&gt;

&lt;p&gt;You must have already noticed that the name &lt;strong&gt;MapReduce&lt;/strong&gt; is made up of two parts: &lt;strong&gt;Map&lt;/strong&gt; and &lt;strong&gt;Reduce&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You might have often used these functions in Python, JavaScript, etc. Something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aL7V6JBX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1695550417835/76197584-24c1-45bc-a9fd-f84545c9ed39.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aL7V6JBX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1695550417835/76197584-24c1-45bc-a9fd-f84545c9ed39.png" alt="Map and Reduce function in JS over an array" width="516" height="284"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Map Function
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Map&lt;/strong&gt; function applies a given function to each element in a collection (such as a list or array) and produces a new collection of transformed values. It is often used to perform element-wise operations on data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reduce Function
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Reduce&lt;/strong&gt; function takes a collection and combines its elements into a single result by repeatedly applying a binary operation. It reduces a collection to a single value.&lt;/p&gt;

&lt;p&gt;Here is a visualization to help you understand it better:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1uf9Sm6q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1695550846214/69628440-7a1d-4c20-ab9b-710cc8f8eaf6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1uf9Sm6q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1695550846214/69628440-7a1d-4c20-ab9b-710cc8f8eaf6.png" alt="" width="800" height="371"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These two methods are fundamental to the Functional Programming Paradigm. I came across these when I started learning functional programming languages like OCaml, Lisp, and Rescript. The main idea is to process the data in a functional, declarative manner.&lt;/p&gt;

&lt;p&gt;Inside the map function, we provide the transformational logic and in the reduce function we provide the aggregator logic, and no need to specify any logic for the looping, etc.&lt;/p&gt;

&lt;p&gt;A large number of problems can actually be split into two broad logic: &lt;strong&gt;Map phase&lt;/strong&gt; and &lt;strong&gt;Reduce phase&lt;/strong&gt;. Some examples mentioned in the paper are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Distributed Grep&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Counting URL access frequency&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reverse Web-Link Graph&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Term-Vector per host&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let me give a simple example, let's say you are working on a Music Recommendation Algorithm. Before you can actually use the data for the recommendation algorithm you will have to do some pre-processing. Usually, logs contain everything, and we may not need all of them, so we have to modify the logs to a form that is relevant to us. To further simplify things, let's say we just need the Genre of the music from the log data. We can use a map function for that.&lt;/p&gt;

&lt;p&gt;Then let's say our recommendation algorithm also needs the number of music the user has listened to for each genre. A reduce function can do this. Here is a sample Python code to help you understand better:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;functools&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nb"&gt;reduce&lt;/span&gt;

&lt;span class="n"&gt;logs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'Shape of You'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;'singer'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'Ed Sheeran'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;'genre'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'pop'&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Uptown Funk"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"singer"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Mark Ronson ft. Bruno Mars"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"genre"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"pop"&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Bohemian Rhapsody"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"singer"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Queen"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"genre"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"rock"&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Friends in Low Places"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"singer"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Garth Brooks"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"genre"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"country"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;update_frequency_count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;freq_dict&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;freq_dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;freq_dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;freq_dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;freq_dict&lt;/span&gt;

&lt;span class="c1"&gt;# Map operation
# {name, singer, genre} -&amp;gt; genre
&lt;/span&gt;&lt;span class="n"&gt;genres&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'genre'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;logs&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="c1"&gt;# genres: ['pop', 'pop', 'rock', 'country']
&lt;/span&gt;
&lt;span class="c1"&gt;# Reduce operation
&lt;/span&gt;&lt;span class="n"&gt;frequency_count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;update_frequency_count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;genres&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frequency_count&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# {'pop': 2, 'rock': 1, 'country': 1}
&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both of these functions are deterministic. Also, the map operation on one element doesn't depend on the result of another operation. In other words, they are independent of each other as well.&lt;/p&gt;

&lt;p&gt;So we can &lt;strong&gt;parallelize the operations&lt;/strong&gt; of Map and Reduce. We can further extend the same thought process by breaking the input data into several chunks of data and having one map function for each chunk of data. This can also solve our &lt;strong&gt;Fault Tolerance issue&lt;/strong&gt; , if something breaks on operation, it won't affect the others cause now they are all running independently in a parallel fashion. We can just re-run the broken process with the small chunk of data. You can see the big picture now as to why the Map and Reduce functions were considered specifically to solve this kind of problem.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6fJF4yCf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1695564417789/694494d8-be8b-4775-ad30-b29d93468d57.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6fJF4yCf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1695564417789/694494d8-be8b-4775-ad30-b29d93468d57.png" alt="" width="800" height="555"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To quote the paper:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Our use of functional model with user specified map and reduce operation allows us to paralelize large computations easily and to use re-execution as the primary mechanism for fault tolerance."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's dive into the programming model deeper and then we will take another very popular example to understand the programming model.&lt;/p&gt;

&lt;p&gt;With MapReduce, we usually deal with key/value pairs cause it's pretty generic. The &lt;strong&gt;Map&lt;/strong&gt; takes an input pair and produces a set of intermediate key/value pairs. The MapReduce library groups all the intermediate values associated with the intermediate key &lt;code&gt;I&lt;/code&gt; and passes them to the &lt;strong&gt;Reduce&lt;/strong&gt; function.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Reduce&lt;/strong&gt; function then accepts the intermediate key &lt;code&gt;I&lt;/code&gt; and a set of values for that key and then merge together values to form a possibly smaller set of values (it can be one as well).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q1sHdS4L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1695570829503/da6f97fa-8bb0-43a4-9a0e-6ffb57e2e849.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q1sHdS4L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1695570829503/da6f97fa-8bb0-43a4-9a0e-6ffb57e2e849.png" alt="" width="800" height="343"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Stages of MapReduce
&lt;/h1&gt;

&lt;p&gt;Now let's dive into the actual working of MapReduce.&lt;/p&gt;

&lt;h2&gt;
  
  
  Splitting the Input
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SsaxmJ93--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1695740855203/59d6634a-c930-420e-aa06-bbaa478a853b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SsaxmJ93--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1695740855203/59d6634a-c930-420e-aa06-bbaa478a853b.png" alt="" width="800" height="853"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The input data is actually partitioned into smaller chunks, typically 16 MB or 64 MB. Let's say the number of chunks/splits is &lt;code&gt;M&lt;/code&gt;. Then there will be &lt;code&gt;M&lt;/code&gt; map operations in total.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Why 64MB?&lt;/em&gt;&lt;/strong&gt; That can be a whole separate topic of discussion but you can think of it like these large amounts of data are usually stored on local disks of the machine that make up the cluster. &lt;strong&gt;Google File System (GFS)&lt;/strong&gt; divides each file into 64MB blocks, so having the input data of the same size will ensure that the map function just has to read data from one block thus reducing I/O latency.&lt;/p&gt;

&lt;p&gt;The Reduce invocations are also distributed by partitioning the intermediate key space into &lt;code&gt;R&lt;/code&gt; pieces using a partitioning function (we will discuss this later in this blog). The number &lt;code&gt;R&lt;/code&gt; is also set by the user.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building the army
&lt;/h2&gt;

&lt;p&gt;When we start the MapReduce function, it first starts a special process called &lt;strong&gt;"master"&lt;/strong&gt;. The master as you might have already guessed does a lot of management-related work like assigning Map and Reduce operations, handling exceptions, etc.&lt;/p&gt;

&lt;p&gt;The program also starts up many copies of the program on the other machines. These are done by the &lt;code&gt;fork&lt;/code&gt; system call. All the other programs except the master are called "worker nodes" or simply "workers". Each of the workers will be assigned a task from the &lt;code&gt;M&lt;/code&gt; map tasks and &lt;code&gt;R&lt;/code&gt; reduce tasks which is determined by the master.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mVHiSf8y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1696057820302/4229a66d-b7cd-4641-901b-f82a398a39ff.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mVHiSf8y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1696057820302/4229a66d-b7cd-4641-901b-f82a398a39ff.png" alt="" width="800" height="621"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Map Stage
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Lz1RWQqK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1695742705418/3d64be6a-e0d9-4f51-b2a3-8bf9dd5b34ff.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Lz1RWQqK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1695742705418/3d64be6a-e0d9-4f51-b2a3-8bf9dd5b34ff.png" alt="" width="800" height="411"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A worker who is assigned a map task reads the contents of the corresponding input split. It parses key/value pairs out of the input data and passes each pair to the user-defined Map function. The intermediate key/value pairs produced by the Map function are buffered in memory. Since the map operation doesn't depend on any other worker, all the map workers can parallelly perform this, thus allowing us to linearly scale the performance of the task of extracting data.&lt;/p&gt;

&lt;p&gt;Before the workers with Reduce task assigned can work, these buffered pairs are written to the local disk which is partitioned into R partitions by the partitioning function. Once the partitioning is completed, the master is informed, who then signals the location to the Reduce workers to get the rest of the job done.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reduce Phase
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zSybh1bW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1696049156179/44877af8-7aaa-4346-9f4d-af1cb1f77023.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zSybh1bW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1696049156179/44877af8-7aaa-4346-9f4d-af1cb1f77023.png" alt="" width="800" height="546"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Reduce workers then read the intermediate data by using RPC calls. Once it has read all the intermediate data, it performs a sort based on the keys. Why?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;So that all the occurrences of the same key are grouped together. The sorting is needed because typically many different keys map to the same reduce task.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let me be frank, it took me some time to wrap my head around this, and I am still not sure if I got it correctly. So if you think my understanding is wrong please don't hesitate to correct me.&lt;/p&gt;

&lt;p&gt;Previously we saw that we have &lt;code&gt;M&lt;/code&gt; map operations and &lt;code&gt;R&lt;/code&gt; reduce operations. Sometimes the same worker is assigned multiple Reduce jobs. Sorting the data makes it easier for the worker to distinguish between the new intermediate data and the old intermediate data. Once the worker finds that the partition has some new data it starts the reduce job again.&lt;/p&gt;

&lt;p&gt;In the reduce step it also performs a merge of all the values corresponding to a particular key. So, sorting the keys makes it easier to merge. This will get clear once we go through the steps again taking the example of a word counter.&lt;/p&gt;

&lt;p&gt;Finally, the reduce worker goes through the sorted intermediate data and for each unique intermediate key, it passes the key and the set of intermediate values to the user's Reduce function. The output is then appended to the final output file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Last stage
&lt;/h2&gt;

&lt;p&gt;When all the Reduce workers have completed execution, the master passes control back to the user program. The output of MapReduce is stored in the &lt;code&gt;R&lt;/code&gt; output files that the &lt;code&gt;R&lt;/code&gt; reduce workers created.&lt;/p&gt;

&lt;h1&gt;
  
  
  Partitioning Function
&lt;/h1&gt;

&lt;p&gt;Let's understand what the partitioning function is all about. As a user, you can define the number of output files you want your data to split between. That number is denoted as &lt;code&gt;R&lt;/code&gt; and MapReduce will assign the same number of Reduce workers. So if &lt;code&gt;R = 10&lt;/code&gt;, it means that MapReduce will partition the data from the map workers into 10 splits. Each split will be assigned to one Reduce worker which means that there will be 10 Reduce workers. And then each Reduce worker will write the output to a file so the user will have their processed data split into 10 files.&lt;/p&gt;

&lt;p&gt;By default, the partitioning algorithm that is used is &lt;code&gt;hash(key) mod R&lt;/code&gt;. This usually gives a fairly balanced partition. In some situations, you might want to use a custom function as well. Taking the example from the paper, if your keys are a bunch of URLs and you want them to be partitioned based on the hostname, then you can use a function that extracts the hostname and then applies the hash and mod. So something like: &lt;code&gt;hash(getHostName(key)) mod R&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Example
&lt;/h1&gt;

&lt;p&gt;Let's take the example of the Character Count. We have an input text file with a bunch of words and we have to calculate the frequency of all the characters appearing in the input.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TxcohUph--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1696054925752/e9ad81cd-4648-4843-beff-ef692f96a83b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TxcohUph--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1696054925752/e9ad81cd-4648-4843-beff-ef692f96a83b.png" alt="" width="800" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, first, we have the input data being split into M partitions. In our case M = 5. So the master worker will assign 5 map workers to map each of these input partitions using the user-defined map function which can be something like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nb"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;document&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
    &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;document&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;each&lt;/span&gt; &lt;span class="n"&gt;char&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;EmitIntermediate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, for the text "apple" our map function will return:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, the intermediate output will be "shuffled" by using our partitioning algorithm. Since we are going to consider only the lowercase English alphabet we can have R = 26 for our partitioning algorithm. That way each output will contain the count of one letter. Simply put, our partitioning function will group all the &lt;code&gt;a&lt;/code&gt;'s and then pass it to our reducer function.&lt;/p&gt;

&lt;p&gt;So, in our case, the reducer function will get the following input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we want the total count, we can have a reducer function like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nb"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;String&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Iterator&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;word&lt;/span&gt;
    &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;counts&lt;/span&gt;
    &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;each&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;Emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;AsString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will give us the final result: &lt;code&gt;a: 6&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So this was a very basic overview of the MapReduce workflow. Keep in mind, that this is not a very generic parallel programming paradigm but only applies to problems that fit into these map-reduce paradigms. But from my work experience, I have seen that a lot of the data analysis work does actually fall into this category. Otherwise, why would Google come up with this in the first place xD.&lt;/p&gt;

&lt;p&gt;There are many more technical concepts of MapReduce that I didn't cover in this blog. Do go through the research paper for an even more in-depth analysis. In case you have any doubts, feel free to ping me or put them in the comments.&lt;/p&gt;




&lt;p&gt;Hope you liked my blog, follow me for more such content. You can learn more about me at &lt;a href="http://arnabsen.dev/about"&gt;&lt;strong&gt;arnabsen.dev/about&lt;/strong&gt;&lt;/a&gt;. You can find my social links at &lt;a href="https://www.arnabsen.dev/links"&gt;arnabsen.dev/links&lt;/a&gt;. Have a nice day.&lt;/p&gt;

</description>
      <category>distributedsystems</category>
      <category>systemdesign</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>A beginner-friendly introduction to Docker and Containers</title>
      <dc:creator>Arnab Sen</dc:creator>
      <pubDate>Sun, 28 May 2023 05:54:21 +0000</pubDate>
      <link>https://dev.to/arnabsen1729/a-beginner-friendly-introduction-to-docker-and-containers-on2</link>
      <guid>https://dev.to/arnabsen1729/a-beginner-friendly-introduction-to-docker-and-containers-on2</guid>
      <description>&lt;h2&gt;
  
  
  What is a Container?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S6rgFG_O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://arnabsen.dev/images/docker-and-containers/cover.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S6rgFG_O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://arnabsen.dev/images/docker-and-containers/cover.jpg" alt="img" width="800" height="531"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might be familiar with these containers.&lt;/p&gt;

&lt;p&gt;These are used for storing stuff and shipping from one place to another. In DevOps, containers have similar applications as well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A Container is a way to package an application with all the necessary dependencies and configuration.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And that package can be portable easily, which makes the process of development and the job of a developer easier.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What happens in these containers?&lt;/strong&gt; Nothing much, just a couple of processes run in isolation on a shared kernel.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How is it isolated?&lt;/strong&gt; The isolation of containers is provided by a Linux feature called &lt;em&gt;namespaces&lt;/em&gt;. Namespaces partitions kernel resources such that one set of processes sees one set of resources while another set of processes sees a different set of resources. They give the group of running processes an isolated view of the kernel. For example,&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Namespaces&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PID&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;process IDs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;USER&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;user and group IDs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;UTS&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;hostname and domain name&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;NS&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;mount points&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;NET&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Network devices, stacks, ports&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;You can use the command &lt;code&gt;lsns&lt;/code&gt; to get lists of all the currently accessible namespaces.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ lsns
        NS TYPE NPROCS PID USER COMMAND
4026531835 cgroup 85 1571 seth /usr/lib/systemd/systemd --user
4026531836 pid 85 1571 seth /usr/lib/systemd/systemd --user
4026531837 user 80 1571 seth /usr/lib/systemd/systemd --user
4026532601 user 1 6266 seth /usr/lib64/firefox/firefox [...]
4026532928 net 1 7164 seth /usr/lib64/firefox/firefox [...]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another feature of the &lt;strong&gt;kernel&lt;/strong&gt; is &lt;em&gt;control groups&lt;/em&gt; (a.k.a &lt;code&gt;cgroups&lt;/code&gt;) which monitors, limits, accounts for, and isolates the resource usage of a collection of processes (also known as containers)&lt;/p&gt;

&lt;h2&gt;
  
  
  Virtual Machine VS Containers
&lt;/h2&gt;

&lt;p&gt;An operating system has two main layers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;OS Kernel:&lt;/strong&gt; It communicates with hardware like memory, CPU .etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Applications Layer:&lt;/strong&gt; They run on the Kernel.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Linux is a kernel. There are many Linux distributions each looking different from one another because the applications are different. But under the hood, they use the same kernel i.e. Linux.&lt;/p&gt;

&lt;p&gt;Coming back to the difference between VM and Containers:-&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kRJgAYW---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://arnabsen.dev/images/docker-and-containers/containers-vs-virtual-machines.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kRJgAYW---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://arnabsen.dev/images/docker-and-containers/containers-vs-virtual-machines.jpg" alt="img" width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;VM runs on something called &lt;em&gt;Hypervisor&lt;/em&gt;. Each virtual machine includes a full-blown OS and its process, which are very heavy and slow to start.&lt;/p&gt;

&lt;p&gt;Containers on the other hand don't include full-blown OS, only include a set of OS-specific files. They are just processes that share the same kernel with other containers and the isolation by the containers is provided by the Linux namespaces. So since they run on top of the kernel they are very fast and also light-weight. So, we are getting the benefits of isolation by VM without the heaviness that comes with VM&lt;/p&gt;

&lt;p&gt;But remember:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Containers don't replace VMs. Both have their own purpose.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is Docker?
&lt;/h2&gt;

&lt;p&gt;An early implementation of container technology was added to &lt;strong&gt;FreeBSD&lt;/strong&gt; in &lt;strong&gt;2001&lt;/strong&gt;. Whereas Docker debuted to the public in &lt;strong&gt;Santa Clara at PyCon in 2013&lt;/strong&gt; and was made open source in &lt;strong&gt;March 2013&lt;/strong&gt;. The tooling for using Linux Containers was really lacking and that's where docker comes into play. Basically, &lt;strong&gt;docker is tooling to manage containers.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Docker allows developers to package their applications into containers and directly use them in their CI/CD pipeline.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It helps achieve:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Build once, run everywhere&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why should we at all bother?
&lt;/h2&gt;

&lt;p&gt;There are a number of advantages of using Docker and Containerisation: (No wonder it is very popular)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You can't say "But... It works on my machine" anymore. Good Luck with that. Because we are packaging the application with all the dependencies and the configurations required, even if it is running on a different machine it will still behave the same way.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i9y6Sh8P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://arnabsen.dev/images/docker-and-containers/works-on-my-machine.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i9y6Sh8P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://arnabsen.dev/images/docker-and-containers/works-on-my-machine.jpeg" alt="Meme" width="800" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;They are very lightweight and fast.&lt;/strong&gt; Already discussed this, just adding one thing. The fact that dockers are lightweight is the main reason behind them being so portable. &lt;em&gt;Obvious&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Docker has its own ecosystem&lt;/strong&gt; provided by the community and has many tools that come with it, which helps solve a lot of issues.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Let's get our hands dirty now.&lt;/p&gt;

&lt;p&gt;To install docker you can look into the &lt;a href="https://docs.docker.com/"&gt;official docs&lt;/a&gt;. Else if you want to just try your hands first, then you can use this: &lt;a href="https://labs.play-with-docker.com/"&gt;https://labs.play-with-docker.com/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Practical 1
&lt;/h2&gt;

&lt;p&gt;Let's go through some popular docker commands. The docker commands are the same for all environments so it won't be an issue.&lt;/p&gt;

&lt;h3&gt;
  
  
  Run a container
&lt;/h3&gt;

&lt;p&gt;Run this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container run &lt;span class="nt"&gt;-t&lt;/span&gt; ubuntu &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;docker container run&lt;/code&gt; will run the image that your provided, in this case, it is &lt;code&gt;Ubuntu&lt;/code&gt;. Now if you are running this command for the first time high chances are that the image is not downloaded, so it will show something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Unable to find image &lt;span class="s1"&gt;'ubuntu:latest'&lt;/span&gt; locally
latest: Pulling from library/ubuntu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you notice something here we just mentioned &lt;code&gt;ubuntu&lt;/code&gt; not &lt;code&gt;ubuntu:latest&lt;/code&gt;. If we didn't specify any version it will take the latest version. But if you wanted to use &lt;code&gt;ubuntu 18.04&lt;/code&gt; you can specify it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container run &lt;span class="nt"&gt;-t&lt;/span&gt; ubuntu:18.04 &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will again show:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Unable to find image &lt;span class="s1"&gt;'ubuntu:18.04'&lt;/span&gt; locally
latest: Pulling from library/ubuntu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But this time notice the version. Also in both cases you see an output like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Basically, it is the output of the &lt;code&gt;ls&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;Now let's run this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container run &lt;span class="nt"&gt;-t&lt;/span&gt; ubuntu top
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And open a new shell and continue. If you are using Play with Docker. Then create a new instance, and then ssh into the previous instance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--B_TDU8yG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://arnabsen.dev/images/docker-and-containers/practical-11.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B_TDU8yG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://arnabsen.dev/images/docker-and-containers/practical-11.png" alt="img" width="800" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now type this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6d2a990df65d ubuntu "top" 3 seconds ago Up 2 seconds blissful_austin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command shows you the containers and all the necessary information about it.&lt;/p&gt;

&lt;p&gt;Usually, containers are used for running a process, maybe a server or some application, and soon as the main process exits the container will stop too. So let's create a very simple process.&lt;/p&gt;

&lt;p&gt;So run this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-d&lt;/span&gt; ubuntu &lt;span class="nb"&gt;sleep &lt;/span&gt;300
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yeah, this is our process, we will ask the container to sleep for 300 secs.&lt;/p&gt;

&lt;p&gt;Every container has a unique container id. So in most of the commands which deal with a particular container, we have to provide the container id. Now let's hop into the &lt;em&gt;sleeping container&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; 6d2a990df65d bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;code&gt;6d2a990df65d&lt;/code&gt; is the docker container id in my case. Just do &lt;code&gt;docker ps&lt;/code&gt; look at the container id and paste it there.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It will spawn a bash terminal inside the container. You can run all the basic commands of Ubuntu.&lt;/p&gt;

&lt;p&gt;To get the list of all the containers (even the ones that exited) run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker ps &lt;span class="nt"&gt;-a&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Stop a container
&lt;/h3&gt;

&lt;p&gt;To stop the container we need to use &lt;code&gt;docker stop &amp;lt;container-id-1&amp;gt; &amp;lt;container-id-2&amp;gt;&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker stop 6d2a990df65d d9da0526d987
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To remove containers you can use &lt;code&gt;docker system prune&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;There is a nice collection of important docker commands by &lt;a href="https://gist.github.com/garystafford"&gt;garystafford&lt;/a&gt; &lt;a href="https://gist.github.com/garystafford/f0bd5f696399d4d7df0f"&gt;here&lt;/a&gt; which I find very helpful.&lt;/p&gt;

&lt;h3&gt;
  
  
  Debugging container
&lt;/h3&gt;

&lt;p&gt;Usually, for debugging, we need to look at the logs. For that use the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker logs &amp;lt;container-id&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, &lt;code&gt;docker exec&lt;/code&gt; sometimes helps in the debugging process.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Remember&lt;/strong&gt; that containers use kernel-level features to achieve isolation and that containers run on top of the kernel. Your container is just a group of processes running in isolation on the same host, and you can use the command &lt;code&gt;docker exec&lt;/code&gt; to enter that isolation with the bash process. After you run the command &lt;code&gt;docker exec&lt;/code&gt;, the group of processes running in isolation (in other words, the container) includes &lt;code&gt;sleep&lt;/code&gt; and &lt;code&gt;bash&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Where are all these images stored?
&lt;/h2&gt;

&lt;p&gt;Docker maintains a public repository of all the images called &lt;a href="https://hub.docker.com/"&gt;Dockerhub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Also, you can run more than one container simultaneously.&lt;/p&gt;

&lt;p&gt;While running containers you can do a lot more stuff, like&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;--name&lt;/code&gt; tag will allow you to name the container.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;--detach or -d&lt;/code&gt; will allow you to run the docker in detached mode i.e. in the background.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;--publish or -p&lt;/code&gt; to publish the ports to the host (very important)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can the list of all the options &lt;a href="https://docs.docker.com/engine/reference/commandline/run/#options"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Containers are self-contained and isolated, which means you can avoid potential conflicts between containers with different systems or runtime dependencies. You can run multiple NGINX containers that all have port &lt;code&gt;80&lt;/code&gt; as their default listening ports. If you're exposing the host by using the --publish flag, the ports selected for the host must be unique. Isolation benefits are possible because of Linux namespaces. Running multiple containers on the same host gives us the ability to use the resources (CPU, memory, and so on) available on a single host. This can result in huge cost savings for an enterprise.&lt;/p&gt;

&lt;p&gt;Although running images directly from the Docker Store can be useful at times, it is more useful to create custom images and refer to official images as the starting point for these images.&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker Images and Docker Containers
&lt;/h2&gt;

&lt;p&gt;Now, if you are confused let's look into the differences between &lt;strong&gt;Docker Images&lt;/strong&gt; and &lt;strong&gt;Docker containers&lt;/strong&gt;. A docker image is a tar file or an archive of the filesystem or the container. It contains the metadata of the filesystem.&lt;/p&gt;

&lt;p&gt;Whereas Container is the running environment of the image. It's the process (isolated process to be specific). The filesystem of the container is virtual, i.e. it has its own abstraction.&lt;/p&gt;

&lt;p&gt;Images are used to create containers (more than one). You can consider it as a blueprint. We can share our Docker Image and then we can create containers using the image. We can also push images to the Docker Hub.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to create Docker Image?
&lt;/h2&gt;

&lt;p&gt;To create a Docker image, we use a special file called &lt;code&gt;Dockerfile&lt;/code&gt; (no extension), which consists of a list of commands to build our image. After we have created our image we can pass it to &lt;code&gt;docker build&lt;/code&gt; which will build the image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build &lt;span class="nt"&gt;-f&lt;/span&gt; Dockerfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A Docker Image is a set of layers where each layer represents an instruction from the Dockerfile. The layers are stacked on top of each other. Each new layer is only a set of differences from the previous one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AseANSeZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://arnabsen.dev/images/docker-and-containers/image-layer.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AseANSeZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://arnabsen.dev/images/docker-and-containers/image-layer.png" alt="img" width="660" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The best part of the image layer is that they are cached. If you change say the 5th line then the docker engine will reuse the first 4 layers and then start building from the 5th line. This improves the time during build and also in the context of CI/CD once the base is pushed, the subsequent pushes will be very fast. To optimize the caching, we need to organize the Dockerfile in a way that the line that will change the most is located at the bottom of the Dockerfile.&lt;/p&gt;

&lt;p&gt;Let's dive into this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practical 2
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Creating flask application
&lt;/h3&gt;

&lt;p&gt;We are going to create a simple Flask application.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Download this Python script &lt;a href="https://gist.github.com/arnabsen1729/1fa19228e4451963bbb64563da98f880"&gt;https://gist.github.com/arnabsen1729/1fa19228e4451963bbb64563da98f880&lt;/a&gt; and save it as &lt;code&gt;app.py&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install the package &lt;code&gt;flask&lt;/code&gt; by &lt;code&gt;pip3 install flask&lt;/code&gt; and run the app &lt;code&gt;python3 app.py&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When the app is running you can visit your &lt;code&gt;0.0.0.0:5000&lt;/code&gt;, you will see &lt;code&gt;hello world!&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hence we have set up a basic Flask server. To close this process press &lt;code&gt;Ctrl+C&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now we will dockerize this flask app.&lt;/p&gt;

&lt;h3&gt;
  
  
  Building Dockerfile
&lt;/h3&gt;

&lt;p&gt;So create a file &lt;code&gt;Dockerfile&lt;/code&gt; and open your text editor and paste this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; python:3.6.1-alpine&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;flask
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["python","app.py"]&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; app.py /app.py&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's go through this line by line&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;FROM python:3.6.1-alpine&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This is the starting point for your Dockerfile. Every Dockerfile typically starts with a &lt;code&gt;FROM&lt;/code&gt; line that is the starting image to build your layers on top of. In this case, you are selecting the &lt;code&gt;python:3.6.1-alpine&lt;/code&gt; base layer because it already has the version of Python and pip that you need to run your application. The Alpine version means that it uses the Alpine distribution, which is significantly smaller than an alternative flavour of Linux. A smaller image means it will download (deploy) much faster, and it is also more secure because it has a smaller attack surface.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;It is highly recommended to only use official images found in the Docker Hub, or noncommunity images found in the Docker Store.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;RUN pip install flask&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;RUN&lt;/code&gt; the command executes commands needed to set up your image for your application, such as installing packages, editing files, or changing file permissions. In this case, you are installing Flask. The &lt;code&gt;RUN&lt;/code&gt; commands are executed at build time and are added to the layers of your image. Usually for node applications, this will involve installing all the &lt;code&gt;node_modules&lt;/code&gt;, if it was a larger Python application, you will have to install those as well.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CMD ["python", "app.py"]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CMD&lt;/code&gt; is the command that is executed when you start a container. Here, you are using CMD to run your Python application. There can be only one &lt;code&gt;CMD&lt;/code&gt; per Dockerfile.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;If you specify more than one CMD, then the last CMD will take effect.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;COPY app.py /app.py&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This line copies the &lt;code&gt;app.py&lt;/code&gt; file in the local directory (where you will run the docker image build) into a new layer of the image. This instruction is the last line in the Dockerfile. Layers that change frequently, such as copying source code into the image, should be placed near the bottom of the file to take full advantage of the Docker layer cache. This allows you to avoid rebuilding layers that could otherwise be cached. For instance, if there was a change in the FROM instruction, it will invalidate the cache for all subsequent layers of this image. You'll see this a little later in this lab&lt;/p&gt;

&lt;p&gt;But, how can the CMD command run if we are copying the &lt;code&gt;app.py&lt;/code&gt; later? &lt;strong&gt;CMD is the command that is executed when you start a container&lt;/strong&gt; , until and unless you run the container it is not executed. Also since the command to run the application will not change, we have placed it higher.&lt;/p&gt;

&lt;p&gt;Here is the list of &lt;a href="https://docs.docker.com/engine/reference/builder/"&gt;all commands&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now to build the image with the &lt;code&gt;Dockerfile&lt;/code&gt; run&lt;/p&gt;

&lt;h3&gt;
  
  
  Running the container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker build &lt;span class="nt"&gt;-t&lt;/span&gt; flask-app &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="c"&gt;# if the Dockefile is in that directory&lt;/span&gt;
&lt;span class="c"&gt;#or&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;docker build &lt;span class="nt"&gt;-t&lt;/span&gt; flask-app &lt;span class="nt"&gt;-f&lt;/span&gt; /path/to/Dockerfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will pull the &lt;code&gt;Python:3.6.1-alpine&lt;/code&gt;, and go through the process. In the end it will output something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Successfully built 38f35dd1d2a4
Successfully tagged flask-app:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now run the command &lt;code&gt;docker images&lt;/code&gt; and you will see &lt;code&gt;flask-app&lt;/code&gt; or whatever name you mentioned in the list. So now you have successfully created the image.&lt;/p&gt;

&lt;p&gt;For the final part let's run the container with this image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-p5001&lt;/span&gt;:5000 &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; flask-container flask-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What are we doing here?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;docker run&lt;/code&gt; to run the container&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;-p5001:5000&lt;/code&gt; to map port 5000 of our container with 5001 of the host machine&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;--name flask-container&lt;/code&gt; giving the name of my container&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;flask-app&lt;/code&gt; the image we want to build&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now do &lt;code&gt;docker ps&lt;/code&gt; you will see&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
940f215ceea0 flask-app &lt;span class="s2"&gt;"python app.py"&lt;/span&gt; 2 seconds ago Up 2 seconds 0.0.0.0:5000-&amp;gt;5001/tcp flask-container
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now go to &lt;code&gt;localhost:5001&lt;/code&gt;, if everything was correct you will see &lt;code&gt;hello world!&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To check the logs we can run &lt;code&gt;docker logs&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker logs flask-container
 &lt;span class="k"&gt;*&lt;/span&gt; Serving Flask app &lt;span class="s2"&gt;"app"&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;lazy loading&lt;span class="o"&gt;)&lt;/span&gt;
 &lt;span class="k"&gt;*&lt;/span&gt; Environment: production
   WARNING: This is a development server. Do not use it &lt;span class="k"&gt;in &lt;/span&gt;a production deployment.
   Use a production WSGI server instead.
 &lt;span class="k"&gt;*&lt;/span&gt; Debug mode: off
 &lt;span class="k"&gt;*&lt;/span&gt; Running on http://0.0.0.0:5000/ &lt;span class="o"&gt;(&lt;/span&gt;Press CTRL+C to quit&lt;span class="o"&gt;)&lt;/span&gt;
172.17.0.1 - - &lt;span class="o"&gt;[&lt;/span&gt;03/Jan/2021 14:55:58] &lt;span class="s2"&gt;"GET / HTTP/1.1"&lt;/span&gt; 200 -
172.17.0.1 - - &lt;span class="o"&gt;[&lt;/span&gt;03/Jan/2021 14:55:59] &lt;span class="s2"&gt;"GET / HTTP/1.1"&lt;/span&gt; 200 -
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Docker images contain all the dependencies that they need to run an application within the image. This is useful because you no longer need to worry about environment drift (version differences) when you rely on dependencies that are installed on every environment you deploy to. You also don't need to follow more steps to provide these environments. Just one step: install docker, and that's it.&lt;/p&gt;

&lt;p&gt;Now if you change the &lt;code&gt;app.py&lt;/code&gt; only the last step in Dockerfile needs to be updated the rest is already cached.&lt;/p&gt;

&lt;p&gt;And you have successfully dockerized your application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker Compose
&lt;/h2&gt;

&lt;p&gt;Sometimes the docker run command becomes very long and very tedious like sometimes we even need to specify lots of environment variables and stuff. Running those long commands every single time becomes difficult. Also if you are working with let's say 3 or 4 containers then you have to write such long-run commands every single time you want to start the container. So there is a simple way to express the commands in a structured way, save it in a file and simply run that file.&lt;/p&gt;

&lt;p&gt;That file is the &lt;code&gt;docker-compose.yml&lt;/code&gt;. The file is a YAML file. (&lt;em&gt;Fun fact: full form of YAML is 'YAML Ain't Markup Language' recursive huh!!&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;Writing a &lt;code&gt;docker-compose&lt;/code&gt; file is not very difficult, you just need to know how to structure it. This article written by Gabriel Tanner explains it nicely.&lt;/p&gt;

&lt;p&gt;Link to the article: &lt;a href="https://gabrieltanner.org/blog/docker-compose"&gt;gabrieltanner.org/blog/docker-compose&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article, we learned about Docker and how to dockerize a simple application. We also learned about Docker Compose and how to use it.&lt;/p&gt;

&lt;p&gt;A really nice collection of Docker study material is available here: &lt;a href="https://docker.farhan.info/"&gt;Docker Handbook 2021 Edition&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you liked my article, do follow me on Dev.to and on Twitter (handle: &lt;a class="mentioned-user" href="https://dev.to/arnabsen1729"&gt;@arnabsen1729&lt;/a&gt;) for updates.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>devops</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>Quick HTML tips: Enhancing UX and Accessibility with `enterkeyhint`.</title>
      <dc:creator>Arnab Sen</dc:creator>
      <pubDate>Thu, 25 May 2023 12:25:27 +0000</pubDate>
      <link>https://dev.to/arnabsen1729/quick-html-tips-enhancing-ux-and-accessibility-with-enterkeyhint-3n06</link>
      <guid>https://dev.to/arnabsen1729/quick-html-tips-enhancing-ux-and-accessibility-with-enterkeyhint-3n06</guid>
      <description>&lt;p&gt;In the world of web development, creating a delightful user experience (UX) goes hand in hand with ensuring accessibility for all users. &lt;strong&gt;Accessibility&lt;/strong&gt; , often referred to as " &lt;strong&gt;a11y&lt;/strong&gt;" (short for "accessibility" and the 11 letters between the "a" and "y"), focuses on making web content usable by individuals with disabilities. While major accessibility considerations involve things like proper semantic structure and alternative text for images, even small details can significantly impact the overall user experience. One such detail is the &lt;code&gt;enterkeyhint&lt;/code&gt; attribute in HTML.&lt;/p&gt;

&lt;p&gt;While using various apps on your smartphones, you might have noticed that the button where we usually have "enter", sometimes gets replaced with terms like "search", "next", etc. This small thing might be insignificant but still gives a lot of clarity about what's going to happen next. Ever wondered how that is implemented?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PywHMs4F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1685000903849/c013279d-539c-4248-b8fc-dbf029da143e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PywHMs4F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1685000903849/c013279d-539c-4248-b8fc-dbf029da143e.png" alt="3 different keywords showing 3 different actions" width="800" height="513"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's through the &lt;code&gt;enterkeyhint&lt;/code&gt; attribute in HTML.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;enterkeyhint&lt;/code&gt; attribute provides a means for developers to communicate the expected action to the browser when the user presses the Enter key within a form. By utilizing this attribute effectively, developers can enhance both the UX and accessibility of web forms. By guiding the browser to understand the intended action, users can navigate forms more easily, without relying solely on mouse or touch input.&lt;/p&gt;

&lt;p&gt;So, let's dive in and explore how this seemingly minor attribute can contribute to a more inclusive and user-friendly web!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the &lt;code&gt;enterkeyhint&lt;/code&gt; attribute?
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;enterkeyhint&lt;/code&gt; attribute is an HTML attribute that can be added to form input elements such as &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;textarea&amp;gt;&lt;/code&gt;. It is used to suggest to the browser the type of action that should be taken when the user presses the Enter key while the input element has focus.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does &lt;code&gt;enterkeyhint&lt;/code&gt; work?
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;enterkeyhint&lt;/code&gt; attribute accepts a few predefined values that represent different actions. Here are the possible values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;enter&lt;/code&gt;: Indicates that the default action for the Enter key should be performed. This is the default value if the attribute is not specified.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;done&lt;/code&gt;: Suggests that pressing Enter should submit the form or perform the action that signifies completion.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;go&lt;/code&gt;: Suggests that pressing Enter should initiate a "go" operation, such as navigating to a URL or starting a search.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;next&lt;/code&gt;: Indicates that pressing Enter should move the input focus to the next input field or control in the form.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;previous&lt;/code&gt;: Suggests that pressing Enter should move the input focus to the previous input field or control in the form.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;search&lt;/code&gt;: Indicates that pressing Enter should initiate a search operation.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The browser may use this hint to display an appropriate keyboard layout or provide other UI cues to the user.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example usage
&lt;/h2&gt;

&lt;p&gt;Let's consider a simple example of a login form to demonstrate the usage of the &lt;code&gt;enterkeyhint&lt;/code&gt; attribute. We have two input fields: one for the username and another for the password. Here's how we can use the &lt;code&gt;enterkeyhint&lt;/code&gt; attribute effectively:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"username"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Username:&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"username"&lt;/span&gt; &lt;span class="na"&gt;enterkeyhint=&lt;/span&gt;&lt;span class="s"&gt;"next"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"password"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Password:&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"password"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"password"&lt;/span&gt; &lt;span class="na"&gt;enterkeyhint=&lt;/span&gt;&lt;span class="s"&gt;"done"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"Login"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we set the &lt;code&gt;enterkeyhint&lt;/code&gt; attribute for the username input field to &lt;code&gt;"next"&lt;/code&gt; and for the password input field to &lt;code&gt;"done"&lt;/code&gt;. This provides a hint to the browser about the expected action when the user presses the Enter key.&lt;/p&gt;

&lt;p&gt;By setting the &lt;code&gt;enterkeyhint&lt;/code&gt; to &lt;code&gt;"next"&lt;/code&gt; for the username field, we suggest that pressing Enter should move the input focus to the password field. This helps users navigate through the form easily without having to use the mouse or touch input.&lt;/p&gt;

&lt;p&gt;For the password field, we set the &lt;code&gt;enterkeyhint&lt;/code&gt; to &lt;code&gt;"done"&lt;/code&gt;. This indicates that pressing Enter should submit the form or perform the action that signifies completion, which, in this case, is logging in.&lt;/p&gt;

&lt;h2&gt;
  
  
  Browser support
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;enterkeyhint&lt;/code&gt; attribute is supported by all the browsers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KQOOqsWt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1685000008048/ccfba274-e20b-4c68-ae16-0dd44c4d76c0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KQOOqsWt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1685000008048/ccfba274-e20b-4c68-ae16-0dd44c4d76c0.png" alt="Supported by all browsers" width="777" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Source: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/enterkeyhint#browser_compatibility"&gt;developer.mozilla.org/enterkeyhint#browser_compatibility&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here is how all of them look:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RRTLYXGN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1685008949747/31b281f7-33a7-4cf6-a534-f3142db9c14a.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RRTLYXGN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1685008949747/31b281f7-33a7-4cf6-a534-f3142db9c14a.gif" alt="Demo" width="444" height="767"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Hope you learned something new through this blog. Do check out my other blogs and follow me on Twitter at &lt;a href="https://twitter.com/ArnabSen1729"&gt;ArnabSen1729&lt;/a&gt; for more such interesting updates. You can also subscribe to my Hashnode newsletter to get updates every time I publish a new article.&lt;/p&gt;

&lt;p&gt;Have a nice day 😄 👋.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>html</category>
      <category>a11y</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Breaking Captchas with Golang: Leveraging the Power of 2captcha</title>
      <dc:creator>Arnab Sen</dc:creator>
      <pubDate>Mon, 22 May 2023 20:28:52 +0000</pubDate>
      <link>https://dev.to/arnabsen1729/breaking-captchas-with-golang-leveraging-the-power-of-2captcha-5ebk</link>
      <guid>https://dev.to/arnabsen1729/breaking-captchas-with-golang-leveraging-the-power-of-2captcha-5ebk</guid>
      <description>&lt;p&gt;Uncover the techniques to break captchas using Golang and leverage the power of 2captcha, empowering your automated systems with advanced capabilities&lt;/p&gt;




&lt;h2&gt;
  
  
  Understanding the Role of Captchas in Digital Security
&lt;/h2&gt;

&lt;p&gt;In today's digital landscape, where cyber threats lurk around every virtual corner, safeguarding sensitive information is of paramount importance. One crucial tool that plays a pivotal role in enhancing digital security is &lt;strong&gt;captchas&lt;/strong&gt;. Captchas, short for "Completely Automated Public Turing tests to tell Computers and Humans Apart," act as a gatekeeper, effectively distinguishing human users from malicious bots. They were invented in 2000 by Luis von Ahn, Manuel Blum, Nicholas Hopper, and John Langford at Carnegie Mellon University. The original CAPTCHAs were text-based and required users to identify distorted words or letters.&lt;/p&gt;

&lt;p&gt;These ingenious puzzles serve a lot of purposes. They help prevent a variety of attacks like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Spam:&lt;/strong&gt; Spam is unsolicited electronic messages, typically sent in bulk. CAPTCHAs can be used to prevent spam bots from creating accounts or sending messages by requiring users to solve a CAPTCHA before they can create an account or send a message.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DDoS attacks:&lt;/strong&gt; A DDoS attack is a distributed denial-of-service attack. This type of attack is designed to overwhelm a website or online service with so much traffic that it becomes unavailable to legitimate users. CAPTCHAs can be used to prevent DDoS attacks by making it more difficult for attackers to generate large numbers of requests.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Credential stuffing:&lt;/strong&gt; Credential stuffing is a type of attack where attackers try to use stolen login credentials to access multiple accounts. CAPTCHAs can be used to prevent credential stuffing attacks by making it more difficult for attackers to try login credentials on multiple websites.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Phishing:&lt;/strong&gt; Phishing is a type of attack where attackers send fraudulent emails that appear to be from a legitimate source. The goal of phishing is to trick the recipient into clicking on a malicious link or providing personal information. CAPTCHAs can be used to prevent phishing attacks by making it more difficult for attackers to create realistic-looking phishing emails.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Click fraud:&lt;/strong&gt; Click fraud is a type of attack where attackers click on ads without human interaction. This type of attack is used to generate revenue for the attacker. CAPTCHAs can be used to prevent click fraud by making it more difficult for attackers to click on ads without human interaction.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By incorporating captchas, website owners can fortify their defense against various cyber threats, such as spam, fraud, and unauthorized access. The utilization of visual or audio-based challenges, often involving distorted characters or logical tasks, impedes automated programs' ability to infiltrate online platforms.&lt;/p&gt;

&lt;h2&gt;
  
  
  How did Captchas even come into the picture?
&lt;/h2&gt;

&lt;p&gt;Well, this dates back to a paper titled &lt;a href="https://en.wikipedia.org/wiki/Computing_Machinery_and_Intelligence" rel="noopener noreferrer"&gt;"Computing Machinery and Intelligence"&lt;/a&gt; that was published in 1950 by the famous and legendary computer scientist, mathematician, logician, cryptanalyst, philosopher, and theoretical biologist 🤯.&lt;/p&gt;

&lt;p&gt;Are you able to guess who I am talking about?&lt;/p&gt;

&lt;p&gt;Well here is a hint 💡: &lt;em&gt;He is famously regarded as the father of modern computer science&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpf2po0ly8txwryxvqz4r.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpf2po0ly8txwryxvqz4r.jpeg" alt="Alan Turing, when he was 16" width="220" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes, none other than &lt;strong&gt;Alan Turing&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;He asked a question "Can a computer talk like a human?". This question led to an idea for measuring artificial intelligence that would famously come to be known as the Turing test. Turing proposed the following game. A human judge has a text conversation with unseen players and has to evaluate their responses. To pass the test, a computer must be able to replace one of the players without substantially changing the results. In other words, a computer would be considered intelligent if its conversation couldn't be easily distinguished from a human's.&lt;/p&gt;

&lt;p&gt;Believe it or not, this same principle is used today to differentiate between a real human and a bot. You can think of captchas as simplified and automated Turing Test and every time you are able to solve a captcha you are basically passing a mini Turing Test.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;P.S: If you are also a movie buff I would highly encourage you to watch the movie The Imitation Game where Benedict Cumberbatch played the role of Alan Turing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9kadlqiwy1ytqxzwywcv.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9kadlqiwy1ytqxzwywcv.jpeg" alt="Poster of The Imitation Game" width="800" height="1200"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, that you know a brief about how captchas came into the picture, let's learn the different types of captchas.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are the different types of captchas?
&lt;/h2&gt;

&lt;p&gt;You might have across different types of captchas while surfing the internet, here are the broad categories of captchas:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Text CAPTCHA:&lt;/strong&gt; The oldest and most common type of CAPTCHA, this involves inputting text from a distorted or obscured image. The logic here is that humans can interpret obscured text while bots cannot.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Image CAPTCHA:&lt;/strong&gt; This type of CAPTCHA involves identifying specific types of objects or patterns in an image. For instance, a user might be asked to select all squares of a grid containing traffic lights or buses.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Audio CAPTCHA:&lt;/strong&gt; For users with visual impairments, audio CAPTCHAs are used. In this case, a short audio clip is played and the user is asked to type the words or numbers that they hear.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpuvrfsna2xhjh24arlur.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpuvrfsna2xhjh24arlur.png" alt="Different Types of Captchas" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are a bunch of service providers available who allow you to use their captcha services on your websites. Some of the most popular ones include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.google.com/recaptcha/about/" rel="noopener noreferrer"&gt;Google reCAPTCHA&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.hcaptcha.com/" rel="noopener noreferrer"&gt;hCaptcha&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.geetest.com/en/" rel="noopener noreferrer"&gt;GeeTest&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.keycaptcha.com/" rel="noopener noreferrer"&gt;KeyCaptcha&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.leminnow.com/" rel="noopener noreferrer"&gt;Lemin Captcha&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, from a personal point of view I kind of hate solving these captchas, and finding the traffic lights.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2meikfebuz2lxa4myd0z.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2meikfebuz2lxa4myd0z.jpeg" alt="A very popular meme around captchas" width="700" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, I started looking if there were any ways to bypass these irritating captchas and I landed upon a goldmine &lt;a href="https://2captcha.com/" rel="noopener noreferrer"&gt;2captcha&lt;/a&gt;. Turns out, these captchas weren't as secure as I used to believe. Today we will look at a demo of how I ended up writing a script to bypass these captchas.&lt;/p&gt;

&lt;p&gt;But, before that, let's learn about 2Captcha.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is 2Captcha?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvuxsfpmf7zmqekgtjg5s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvuxsfpmf7zmqekgtjg5s.png" alt="2Captcha Logo" width="630" height="166"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2Captcha operates as a real-time CAPTCHA decoding service, proficient in distinguishing and interpreting captchas with accuracy. It leverages human intellect for image recognition tasks, ensuring high levels of precision. Offering compatibility with a wide range of programming languages through its API, 2Captcha can identify and solve a diverse variety of CAPTCHA types. In fact, 2Captcha can actually solve all the captcha types I mentioned above.&lt;/p&gt;

&lt;p&gt;So, without further ado, let's use the Golang module of 2Captcha and build ourselves a CLI tool. You will be amazed to see how easy it is to use this service.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building the Golang CLI tool
&lt;/h2&gt;

&lt;p&gt;So, the first step would be to create an account in 2Captcha and get our API key.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Creating our 2Captcha account
&lt;/h3&gt;

&lt;p&gt;Visit their website &lt;a href="https://2captcha.com/" rel="noopener noreferrer"&gt;https://2captcha.com/&lt;/a&gt; and then sign in with your method of choice. After that, you will land on a page like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9nmqtb99nz2jaknxi5n5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9nmqtb99nz2jaknxi5n5.png" alt="Sign In Page of 2Captcha" width="800" height="693"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select the left option of "I'm a customer" and then you will be redirected to the dashboard where you can see your API key.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feaye96jndivsk5buxlw5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feaye96jndivsk5buxlw5.png" alt="API Page of 2Captcha" width="800" height="419"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, to further move ahead with our project make sure that you have Golang installed in your machine. To check that simply run &lt;code&gt;go version&lt;/code&gt; in the terminal and it should show the version of Golang that is installed. If it gives an error, you will have to install Golang.&lt;/p&gt;

&lt;p&gt;Once you are done with all these we can finally initialize our Golang Project.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Initialize our Golang Project
&lt;/h3&gt;

&lt;p&gt;To get started, let's initialize a new Golang project. Open your terminal or command prompt and follow the steps below:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create a new directory for your project:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;captcha-solver
&lt;span class="nb"&gt;cd &lt;/span&gt;captcha-solver
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Initialize the Go module:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go mod init github.com/your-username/captcha-solver
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Replace &lt;code&gt;your-username&lt;/code&gt; with your actual GitHub username or any other relevant identifier.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a new Go source file named &lt;code&gt;main.go&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;main.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You have now set up the basic structure for your Golang project.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Installing Required Modules
&lt;/h3&gt;

&lt;p&gt;To interact with the 2Captcha service, we need to install the 2captcha-go library. Run the following command to install the required module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go get github.com/2captcha/2captcha-go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The module will be downloaded and added to your project's &lt;code&gt;go.mod&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;Finally, we will write the code for our captcha solver.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. &lt;strong&gt;Building the Captcha Solver&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Now let's proceed with building the captcha solver. Open the &lt;code&gt;main.go&lt;/code&gt; file in a text editor and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"flag"&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"io/ioutil"&lt;/span&gt;
    &lt;span class="s"&gt;"log"&lt;/span&gt;
    &lt;span class="s"&gt;"os"&lt;/span&gt;

    &lt;span class="s"&gt;"github.com/2captcha/2captcha-go"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;apiKey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"&amp;lt;API-KEY&amp;gt;"&lt;/span&gt; &lt;span class="c"&gt;// Replace with your actual API key&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// Parse input arguments&lt;/span&gt;
    &lt;span class="n"&gt;captchaImagePath&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;flag&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"image"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Path to the captcha image file"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;flag&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Parse&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="c"&gt;// Verify that the captcha image path is provided&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;captchaImagePath&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Please provide the captcha image path."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;flag&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PrintDefaults&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c"&gt;// Load the captcha image&lt;/span&gt;
    &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;ioutil&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ReadFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;captchaImagePath&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Failed to read captcha image: %v&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c"&gt;// Initialize the 2Captcha client&lt;/span&gt;
    &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;api2captcha&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c"&gt;// Use the 2Captcha client to solve the captcha&lt;/span&gt;
    &lt;span class="nb"&gt;cap&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;api2captcha&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Normal&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;File&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;captchaImagePath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;captchaText&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Solve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;cap&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ToRequest&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;api2captcha&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ErrTimeout&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fatal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Timeout"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;api2captcha&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ErrApi&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fatal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"API error"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;api2captcha&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ErrNetwork&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fatal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Network error"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fatal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c"&gt;// Output the solved captcha text&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Solved captcha: %s&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;captchaText&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's break down the code and understand each section's functionality.&lt;/p&gt;

&lt;h4&gt;
  
  
  Parsing Input Arguments
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;captchaImagePath&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;flag&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"image"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Path to the captcha image file"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;flag&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Parse&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code uses the &lt;code&gt;flag&lt;/code&gt; package to parse input arguments provided when running the program. We define a flag named &lt;code&gt;image&lt;/code&gt; that represents the path to the captcha image file. The &lt;code&gt;flag.Parse()&lt;/code&gt; function is then called to parse the input arguments.&lt;/p&gt;

&lt;h4&gt;
  
  
  Loading the Captcha Image
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;ioutil&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ReadFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;captchaImagePath&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Failed to read captcha image: %v&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this section, we use the &lt;code&gt;ioutil.ReadFile()&lt;/code&gt; function to load the contents of the captcha image file specified by the user. If there is an error while reading the file, an error message is printed, and the program exits.&lt;/p&gt;

&lt;h4&gt;
  
  
  Initializing the 2Captcha Client
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;api2captcha&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we initialize the 2Captcha client by creating a new instance of api2captcha.Client with the provided API key. Remember to replace the API key with the key that you saw in your dashboard.&lt;/p&gt;

&lt;h4&gt;
  
  
  Solving the Captcha
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="nb"&gt;cap&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;api2captcha&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Normal&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;File&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;captchaImagePath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;captchaText&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Solve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;cap&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ToRequest&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To solve the captcha, we create a &lt;code&gt;Normal&lt;/code&gt; struct instance from the &lt;code&gt;api2captcha&lt;/code&gt; package and pass the captcha image file path to it. Then, we call the &lt;code&gt;Solve()&lt;/code&gt; method of the 2Captcha client, passing the &lt;code&gt;ToRequest()&lt;/code&gt; method's result from the &lt;code&gt;cap&lt;/code&gt; struct as an argument. This method sends the captcha image to the 2Captcha service for solving and returns the solved captcha text.&lt;/p&gt;

&lt;h4&gt;
  
  
  Outputting the Solved Captcha Text
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Solved captcha: %s&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;captchaText&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, we output the solved captcha text to the console using &lt;code&gt;fmt.Printf()&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations! You have successfully built a captcha solver using the 2Captcha service in Golang. You can now run the program by executing the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go run main.go &lt;span class="nt"&gt;--image&lt;/span&gt; /path/to/captcha.png
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;/path/to/captcha.png&lt;/code&gt; with the actual path to your captcha image file. The program will send the image to the 2Captcha service, solve the captcha, and display the solved text.&lt;/p&gt;

&lt;p&gt;Feel free to explore the 2Captcha Go client library documentation (&lt;a href="https://pkg.go.dev/github.com/2captcha/2captcha-go" rel="noopener noreferrer"&gt;&lt;strong&gt;https://pkg.go.dev/github.com/2captcha/2captcha-go&lt;/strong&gt;&lt;/a&gt;) for more advanced usage and options.&lt;/p&gt;

&lt;p&gt;That's it! You can now integrate this captcha solver into your own projects or applications to automate captcha solving using the 2Captcha service.&lt;/p&gt;

</description>
      <category>go</category>
      <category>tutorial</category>
      <category>programming</category>
      <category>development</category>
    </item>
    <item>
      <title>How to debug buggy code? Exploring the debugger GDB</title>
      <dc:creator>Arnab Sen</dc:creator>
      <pubDate>Sun, 21 May 2023 07:15:08 +0000</pubDate>
      <link>https://dev.to/arnabsen1729/how-to-debug-buggy-code-exploring-the-debugger-gdb-5d3i</link>
      <guid>https://dev.to/arnabsen1729/how-to-debug-buggy-code-exploring-the-debugger-gdb-5d3i</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;No matter how big or small the codebase is, errors and bugs are inevitable. So as a developer we should know how to fix them. But, even before fixing an error, we have a more daunting task. Can you guess it? Yes, finding where the error is in the first place.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Debugging&lt;/strong&gt; is the process of detecting and removing existing and potential errors (also called 'bugs') in a software code.&lt;/p&gt;

&lt;p&gt;In our day-to-day programming scenarios, we often use the print statements (like &lt;code&gt;console.log()&lt;/code&gt;) to debug. But imagine this scenario. You are working on a large codebase and compiling the entire code takes like 3-4 mins. Now if you are stuck somewhere and you add a print statement you have to recompile the code. And if you keep doing that repeatedly, you will have to recompile the code every single time you make a change. This is too inefficient and a huge waste of time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643630421381%2F5u8sv4rcE.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1643630421381%2F5u8sv4rcE.png" alt="image.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is where &lt;strong&gt;Debuggers&lt;/strong&gt; come to the rescue. In this article, we will look at &lt;strong&gt;GDB&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is GDB?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;GDB (GNU Debugger)&lt;/strong&gt; is a debugger for C and C++.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;GDB allows you to do things like run the program up to a certain point then stop and print out the values of certain variables at that point, or step through the program one line at a time and print out the values of each variable after executing each line.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;GDB uses a command-line interface which might be intimidating at first but once you get used to the commands it becomes very easy to use. We will explore some of the basic commands in this article.&lt;/p&gt;

&lt;p&gt;Let's start with installing &lt;code&gt;gdb&lt;/code&gt; first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing GDB
&lt;/h2&gt;

&lt;p&gt;If you are using Linux, you probably already have gdb, but if you are using Windows, you will need to install it.&lt;/p&gt;

&lt;p&gt;Check if you already have gdb installed by running the following command in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gdb &lt;span class="nt"&gt;--version&lt;/span&gt; &lt;span class="c"&gt;# if you are in a Unix based system&lt;/span&gt;

c:&lt;span class="se"&gt;\m&lt;/span&gt;ingw&lt;span class="se"&gt;\b&lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt;&lt;span class="se"&gt;\g&lt;/span&gt;db.exe &lt;span class="nt"&gt;--version&lt;/span&gt; &lt;span class="c"&gt;# if you are in windows&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Linux
&lt;/h3&gt;

&lt;p&gt;You can install gdb on Debian-based Linux distro (e.g. Ubuntu, Mint, etc) by the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;gdb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Windows
&lt;/h3&gt;

&lt;p&gt;If you have MinGW installed then you already have &lt;code&gt;gdb&lt;/code&gt;. Otherwise, download the latest MinGW installer from &lt;a href="https://sourceforge.net/projects/mingw/files/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install MinGW from the installer.&lt;/li&gt;
&lt;li&gt;Run the "MinGW Installation Manager" (which might be located in &lt;code&gt;C:\MinGW\libexec\mingw-get\guimain.exe&lt;/code&gt; )&lt;/li&gt;
&lt;li&gt;Make sure that the &lt;code&gt;mingw32-gdb&lt;/code&gt; bin package is installed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After installation is complete, check the version once again with the commands above. Let's get started with debugging a simple program now.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; GDB is good but it isn't very fancy, so instead you can use &lt;a href="https://gef.readthedocs.io/en/master/" rel="noopener noreferrer"&gt;GDB-GEF&lt;/a&gt;. It's very easy to install. I will be using GEF throughout this article and you should use it too.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Starting GDB
&lt;/h2&gt;

&lt;p&gt;To debug we need to have some code. Let's write a simple program to calculate factorial in C.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;
&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;MAX_FACTORIAL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Enter a number: "&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;scanf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%d"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Factorial of %d is %d&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's compile the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gcc&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="n"&gt;factorial&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's run &lt;code&gt;gdb&lt;/code&gt; on the binary file &lt;code&gt;factorial&lt;/code&gt;. We do that by the &lt;code&gt;gdb program&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gdb&lt;/span&gt; &lt;span class="n"&gt;factorial&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do you see some errors like this?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Reading symbols from factorial...
(No debugging symbols found in factorial)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;To quit gdb press &lt;code&gt;Ctrl+C&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is because to prepare our program for debugging with &lt;code&gt;gdb&lt;/code&gt;, we must compile it with the &lt;code&gt;-g&lt;/code&gt; flag. So, let's recompile our program this time with the &lt;code&gt;-g&lt;/code&gt; flag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gcc&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="n"&gt;factorial&lt;/span&gt;
&lt;span class="n"&gt;gdb&lt;/span&gt; &lt;span class="n"&gt;factorial&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we don't see the error &lt;code&gt;(No debugging symbols found in factorial)&lt;/code&gt; anymore. So now we can use &lt;code&gt;gdb&lt;/code&gt; to debug our code.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What gdb did under the hood is that it automatically loaded the symbol table. We will look into Symbol Table later.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Breakpoint
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;breakpoint&lt;/code&gt; is a spot in your program where you would like to temporarily stop execution in order to check the values of variables, or to try to find out where the program is crashing, etc. To set a breakpoint you use the &lt;code&gt;break&lt;/code&gt; command.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Remember:&lt;/strong&gt; Almost all the commonly used gdb commands have a shorter version and we should use them heavily to improve speed.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;break&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;
&lt;span class="cp"&gt;# OR a shorter version
&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;
&lt;span class="n"&gt;Breakpoint&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="mh"&gt;0x117f&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="mf"&gt;15.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means we have set a breakpoint at the &lt;code&gt;main&lt;/code&gt; function so that as soon as the instruction pointer reaches the main function it will stop the execution and wait for our commands.&lt;/p&gt;

&lt;p&gt;To see the list of all the breakpoints use the command &lt;code&gt;info break&lt;/code&gt;. As the command name suggests it will give us information about all the breakpoints we have set.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;
&lt;span class="n"&gt;Num&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;Disp&lt;/span&gt; &lt;span class="n"&gt;Enb&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt; &lt;span class="n"&gt;What&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;keep&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="mh"&gt;0x000000000000117f&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is an index associated with each breakpoint. These index values will be used if you want to delete a breakpoint or disable it. First, let's run the program with the breakpoint set. To run, use the &lt;code&gt;run&lt;/code&gt; command (or just &lt;code&gt;r&lt;/code&gt; as a shorter version).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;
&lt;span class="c1"&gt;// OR&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see the program execution stopped. Let's just resume the execution with the command &lt;code&gt;continue&lt;/code&gt; (or just &lt;code&gt;c&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;
&lt;span class="n"&gt;Continuing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;Enter&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="n"&gt;Factorial&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Inferior&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;process&lt;/span&gt; &lt;span class="mi"&gt;128334&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;exited&lt;/span&gt; &lt;span class="n"&gt;normally&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will notice it will prompt for the number and then display the factorial of that number and exit normally. Why? Because there were no other breakpoints in our code and execution hence didn't stop anywhere else.&lt;/p&gt;

&lt;p&gt;Sometimes, we don't need to stop at a breakpoint so we can disable it. To disable a breakpoint use the &lt;code&gt;disable&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;
&lt;span class="n"&gt;Num&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;Disp&lt;/span&gt; &lt;span class="n"&gt;Enb&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt; &lt;span class="n"&gt;What&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;keep&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="mh"&gt;0x000000000000117f&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;disable&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;
&lt;span class="n"&gt;Num&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;Disp&lt;/span&gt; &lt;span class="n"&gt;Enb&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt; &lt;span class="n"&gt;What&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;keep&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="mh"&gt;0x000000000000117f&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once, disabled you can notice the value under &lt;code&gt;Enb&lt;/code&gt; is not &lt;code&gt;y&lt;/code&gt; anymore. It's &lt;code&gt;n&lt;/code&gt; representing it's not enabled anymore. If you run the program now, you will notice that it didn't stop at any place. This is because the breakpoint is disabled.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;
&lt;span class="n"&gt;Starting&lt;/span&gt; &lt;span class="n"&gt;program&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;home&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;arnab&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;Desktop&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;SWE&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;Lab&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ass2&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;prog&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;factorial&lt;/span&gt;
&lt;span class="n"&gt;Enter&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="n"&gt;Factorial&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Inferior&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;process&lt;/span&gt; &lt;span class="mi"&gt;411121&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;exited&lt;/span&gt; &lt;span class="n"&gt;normally&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sometimes, we add a breakpoint to a function inside the loop. And we don't want to stop for every iteration of the loop. In that scenario, we can ignore the breakpoint for a fixed number of times using the &lt;code&gt;ignore&lt;/code&gt; command. Let's try that. We have a loop in our &lt;code&gt;factorial()&lt;/code&gt; function. Let's add a breakpoint to the loop.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TIP:&lt;/strong&gt; You can see the code of a function directly from the gdb terminal using the &lt;code&gt;list&lt;/code&gt; command. So do &lt;code&gt;list factorial&lt;/code&gt; and it will display the source code of &lt;code&gt;factorial()&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We want to set the breakpoint at line 8 of this &lt;code&gt;main.c&lt;/code&gt; file. So, we will use the command &lt;code&gt;b main.c:8&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt; &lt;span class="n"&gt;our&lt;/span&gt; &lt;span class="n"&gt;breakpoints&lt;/span&gt;
&lt;span class="n"&gt;Num&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;Disp&lt;/span&gt; &lt;span class="n"&gt;Enb&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt; &lt;span class="n"&gt;What&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;keep&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="mh"&gt;0x000000000000117f&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt; &lt;span class="n"&gt;factorial&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;see&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="n"&gt;include&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;stdio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;MAX_FACTORIAL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;4&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;I&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;--&lt;/span&gt; &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;here&lt;/span&gt;
&lt;span class="mi"&gt;9&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="mi"&gt;11&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="n"&gt;add&lt;/span&gt; &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;
&lt;span class="n"&gt;Breakpoint&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="mh"&gt;0x115c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="mf"&gt;8.&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;check&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;was&lt;/span&gt; &lt;span class="n"&gt;added&lt;/span&gt;
&lt;span class="n"&gt;Num&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;Disp&lt;/span&gt; &lt;span class="n"&gt;Enb&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt; &lt;span class="n"&gt;What&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;keep&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="mh"&gt;0x000000000000117f&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;
&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;keep&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="mh"&gt;0x000000000000115c&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;factorial&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if you run the program with the &lt;code&gt;r&lt;/code&gt; command. It will prompt you for a number (enter something like 5). You will then see it hits the breakpoint at the &lt;code&gt;factorial()&lt;/code&gt; function (Remember we disabled the breakpoint at the &lt;code&gt;main()&lt;/code&gt; function). Type the command &lt;code&gt;continue&lt;/code&gt; or &lt;code&gt;c&lt;/code&gt; and it will again hit the same point. Cause not we are now inside a loop. Keep doing this 5 times. Finally, when the loop ends you will notice the factorial result is displayed.&lt;/p&gt;

&lt;p&gt;In this scenario, if we want to ignore the breakpoint for the first 4 times maybe. We will use the &lt;code&gt;ignore &amp;lt;index of breakpoint&amp;gt; 4&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;
&lt;span class="n"&gt;Num&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;Disp&lt;/span&gt; &lt;span class="n"&gt;Enb&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt; &lt;span class="n"&gt;What&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;keep&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="mh"&gt;0x000055555555517f&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;
&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;keep&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="mh"&gt;0x000055555555515c&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;factorial&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;
 &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;already&lt;/span&gt; &lt;span class="n"&gt;hit&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="n"&gt;times&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;ignore&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
&lt;span class="n"&gt;Will&lt;/span&gt; &lt;span class="n"&gt;ignore&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="n"&gt;crossings&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="mf"&gt;2.&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;
&lt;span class="n"&gt;Num&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;Disp&lt;/span&gt; &lt;span class="n"&gt;Enb&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt; &lt;span class="n"&gt;What&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;keep&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="mh"&gt;0x000055555555517f&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;
&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;keep&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="mh"&gt;0x000055555555515c&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;factorial&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;
 &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;already&lt;/span&gt; &lt;span class="n"&gt;hit&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="n"&gt;times&lt;/span&gt;
 &lt;span class="n"&gt;ignore&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="n"&gt;hits&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's run the program. This time when it prompts for a number, we will enter 5. After that, it will hit the breakpoint at the &lt;code&gt;factorial()&lt;/code&gt; function. Press &lt;code&gt;c&lt;/code&gt; to continue, and the program ends. This is because gdb ignored the breakpoint for the first 4 times and only hit the 5-th time we hit the breakpoint.&lt;/p&gt;

&lt;p&gt;Now, let's delete that breakpoint using the command &lt;code&gt;delete breakpoints &amp;lt;index&amp;gt;&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;
&lt;span class="n"&gt;Num&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;Disp&lt;/span&gt; &lt;span class="n"&gt;Enb&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt; &lt;span class="n"&gt;What&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;keep&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="mh"&gt;0x000055555555517f&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;
&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;keep&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="mh"&gt;0x000055555555515c&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;factorial&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;
 &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;already&lt;/span&gt; &lt;span class="n"&gt;hit&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="n"&gt;times&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;
&lt;span class="n"&gt;Num&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;Disp&lt;/span&gt; &lt;span class="n"&gt;Enb&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt; &lt;span class="n"&gt;What&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;keep&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="mh"&gt;0x000055555555517f&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;
&lt;span class="n"&gt;No&lt;/span&gt; &lt;span class="n"&gt;breakpoints&lt;/span&gt; &lt;span class="n"&gt;or&lt;/span&gt; &lt;span class="n"&gt;watchpoints&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Symbol Table
&lt;/h2&gt;

&lt;p&gt;Have you ever wondered how a compiler remembers which data structure is of which type and so on? Well, the answer is &lt;strong&gt;Symbol Table&lt;/strong&gt;. It is a data structure used by a compiler to keep track of semantics of variable names like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Data type&lt;/strong&gt; of the variable.&lt;/li&gt;
&lt;li&gt;When is used: &lt;strong&gt;scope&lt;/strong&gt; (The effective context where a name is valid).&lt;/li&gt;
&lt;li&gt;Where it is stored: &lt;strong&gt;storage address&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In gdb, when you run &lt;code&gt;gdb factorial&lt;/code&gt; it will load the symbol table. Let's quit the gdb now by pressing &lt;code&gt;Ctrl+C&lt;/code&gt; or typing &lt;code&gt;q&lt;/code&gt; and Enter. This time just run &lt;code&gt;gdb&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To load a program and its symbol table use the command &lt;code&gt;file &amp;lt;program&amp;gt;&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;prog&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;factorial&lt;/span&gt;
&lt;span class="n"&gt;Reading&lt;/span&gt; &lt;span class="n"&gt;symbols&lt;/span&gt; &lt;span class="n"&gt;from&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;prog&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that it has read the symbols, we can interact with them. Run the command &lt;code&gt;info address &amp;lt;symbol name&amp;gt;&lt;/code&gt; to see the address of that symbol.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;
&lt;span class="n"&gt;Symbol&lt;/span&gt; &lt;span class="s"&gt;"main"&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;function&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt; &lt;span class="mh"&gt;0x1177&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt; &lt;span class="n"&gt;factorial&lt;/span&gt;
&lt;span class="n"&gt;Symbol&lt;/span&gt; &lt;span class="s"&gt;"factorial"&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;function&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt; &lt;span class="mh"&gt;0x1145&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt; &lt;span class="n"&gt;MAX_FACTORIAL&lt;/span&gt;
&lt;span class="n"&gt;Symbol&lt;/span&gt; &lt;span class="s"&gt;"MAX_FACTORIAL"&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;storage&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt; &lt;span class="mh"&gt;0x2004&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now since you know the address you can reverse lookup the symbol name with the command &lt;code&gt;info symbol &amp;lt;address&amp;gt;&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="n"&gt;symbol&lt;/span&gt; &lt;span class="mh"&gt;0x1177&lt;/span&gt;
&lt;span class="n"&gt;main&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;section&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="n"&gt;symbol&lt;/span&gt; &lt;span class="mh"&gt;0x1145&lt;/span&gt;
&lt;span class="n"&gt;factorial&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;section&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The best part of this &lt;code&gt;info symbol&lt;/code&gt; is that if you don't specify the exact address, show the offset from the beginning of the symbol. So in my case, the &lt;code&gt;main&lt;/code&gt; symbol is at address &lt;code&gt;0x1177&lt;/code&gt;. So let's try to see what the symbol name of the address &lt;code&gt;0x1180&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="n"&gt;symbol&lt;/span&gt; &lt;span class="mh"&gt;0x1180&lt;/span&gt;
&lt;span class="n"&gt;main&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;section&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, remember we had a variable called &lt;code&gt;val&lt;/code&gt; in main. Let's see the address of that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;
&lt;span class="n"&gt;No&lt;/span&gt; &lt;span class="n"&gt;symbol&lt;/span&gt; &lt;span class="s"&gt;"val"&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means we are not in the correct scope yet. Because the variable &lt;code&gt;val&lt;/code&gt; was declared inside the &lt;code&gt;main()&lt;/code&gt; function, we cannot access it outside the &lt;code&gt;main()&lt;/code&gt; function. So let's set a breakpoint at the main and run the program and then we will see the address of &lt;code&gt;val&lt;/code&gt; in the symbol table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;
&lt;span class="n"&gt;Breakpoint&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="mh"&gt;0x117f&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="mf"&gt;15.&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;
&lt;span class="n"&gt;Symbol&lt;/span&gt; &lt;span class="s"&gt;"val"&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;complex&lt;/span&gt; &lt;span class="n"&gt;DWARF&lt;/span&gt; &lt;span class="n"&gt;expression&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
     &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;DW_OP_fbreg&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To see the &lt;strong&gt;list of all the functions&lt;/strong&gt; in the symbol table use the command &lt;code&gt;info func&lt;/code&gt;. You can also filter the functions with regexes. Let's search for our &lt;code&gt;factorial&lt;/code&gt; function. The exact regex match will be &lt;code&gt;^facorial$&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="n"&gt;func&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="n"&gt;factorial&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;
&lt;span class="n"&gt;All&lt;/span&gt; &lt;span class="n"&gt;functions&lt;/span&gt; &lt;span class="n"&gt;matching&lt;/span&gt; &lt;span class="n"&gt;regular&lt;/span&gt; &lt;span class="n"&gt;expression&lt;/span&gt; &lt;span class="s"&gt;"^factorial$"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;

&lt;span class="n"&gt;File&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;factorial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can do the same for &lt;strong&gt;global variables&lt;/strong&gt; using the command &lt;code&gt;info var&lt;/code&gt;. Let's look for our global variable &lt;code&gt;MAX_FACTORIAL&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="n"&gt;MAX_FACTORIAL&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;
&lt;span class="n"&gt;All&lt;/span&gt; &lt;span class="n"&gt;variables&lt;/span&gt; &lt;span class="n"&gt;matching&lt;/span&gt; &lt;span class="n"&gt;regular&lt;/span&gt; &lt;span class="n"&gt;expression&lt;/span&gt; &lt;span class="s"&gt;"^MAX_FACTORIAL$"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;

&lt;span class="n"&gt;File&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;MAX_FACTORIAL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The symbol table also stores the type of the variable. We can use the command &lt;code&gt;whatis &amp;lt;variable name&amp;gt;&lt;/code&gt; to see the type of the variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;whatis&lt;/span&gt; &lt;span class="n"&gt;MAX_FACTORIAL&lt;/span&gt;
&lt;span class="n"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;whatis&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;
&lt;span class="n"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Working with Variables
&lt;/h2&gt;

&lt;p&gt;So far we have seen how to set breakpoints, run the program and get the symbol table. Now let's see how to work with variables. Most of the time we don't need all the global variables rather want to see the local variables. For that, we have the command &lt;code&gt;info locals&lt;/code&gt; which will show us the local variables.&lt;/p&gt;

&lt;p&gt;First, let's set a breakpoint after the &lt;code&gt;scanf&lt;/code&gt; statement (which is line number 17 in main.c file). So run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;17&lt;/span&gt;
&lt;span class="n"&gt;Breakpoint&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="mh"&gt;0x11a8&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="mf"&gt;17.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the program is not running press &lt;code&gt;r&lt;/code&gt; (to run) otherwise press &lt;code&gt;c&lt;/code&gt; (to continue). It will show the prompt &lt;code&gt;Enter a number:&lt;/code&gt; to which you should type a value and the program will reach another breakpoint.&lt;/p&gt;

&lt;p&gt;Now run the command to get the local variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="n"&gt;locals&lt;/span&gt;
&lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mh"&gt;0xa&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It says the value of the variable &lt;code&gt;val&lt;/code&gt; is &lt;code&gt;0xa&lt;/code&gt;. We can also print the values with the command &lt;code&gt;print&lt;/code&gt; (or just &lt;code&gt;p&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;
&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mh"&gt;0xa&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;
&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, the value will be in hex, but we can specify &lt;code&gt;/d&lt;/code&gt; to display in decimal. Here are other formats:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;format&lt;/th&gt;
&lt;th&gt;description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;x&lt;/td&gt;
&lt;td&gt;hexadecimal&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;d&lt;/td&gt;
&lt;td&gt;signed decimal&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;u&lt;/td&gt;
&lt;td&gt;unsigned decimal&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;o&lt;/td&gt;
&lt;td&gt;octal&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;t&lt;/td&gt;
&lt;td&gt;binary&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;a&lt;/td&gt;
&lt;td&gt;address, absolute and relative&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;c&lt;/td&gt;
&lt;td&gt;character&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;f&lt;/td&gt;
&lt;td&gt;floating-point&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;We can also set the variable values, using the &lt;code&gt;set variable&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt; &lt;span class="n"&gt;variable&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;
&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Functions
&lt;/h2&gt;

&lt;p&gt;Functions play an important role in programs. So, let's see how gdb handles them. In our code, we have two functions &lt;code&gt;main&lt;/code&gt; and &lt;code&gt;factorial&lt;/code&gt;. So, let's start with setting a breakpoint at &lt;code&gt;main&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;
&lt;span class="n"&gt;Breakpoint&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="mh"&gt;0x117f&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;file&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="mf"&gt;15.&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="k"&gt;break&lt;/span&gt;
&lt;span class="n"&gt;Num&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt; &lt;span class="n"&gt;Disp&lt;/span&gt; &lt;span class="n"&gt;Enb&lt;/span&gt; &lt;span class="n"&gt;Address&lt;/span&gt; &lt;span class="n"&gt;What&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;breakpoint&lt;/span&gt; &lt;span class="n"&gt;keep&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="mh"&gt;0x000000000000117f&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt; &lt;span class="n"&gt;at&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the program with &lt;code&gt;r&lt;/code&gt;. GDB will stop execution at the first line of the function &lt;code&gt;main&lt;/code&gt;. Before moving ahead, let's try to understand the difference between this &lt;code&gt;next&lt;/code&gt; command and another very similar command called &lt;code&gt;stepi&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;next&lt;/code&gt;: execute next line, including any function calls.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;stepi&lt;/code&gt;: step by machine instructions rather than source lines&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, at any point, if we are at a function call, do &lt;code&gt;si&lt;/code&gt; (step into) to enter the function.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TIP :&lt;/strong&gt; You can use a count with &lt;code&gt;next&lt;/code&gt; or &lt;code&gt;stepi&lt;/code&gt; to perform the command multiple times.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We will perform &lt;code&gt;next 2&lt;/code&gt; i.e next twice. This time you will be prompted for a number. After that, we will step into the instruction that will take us to the factorial function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="c1"&gt;// we will be in that line where factorial is called&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;si&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="c1"&gt;// we will be in the factorial function&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="c1"&gt;// the first line of the factorial function&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;We are doing &lt;code&gt;si 3&lt;/code&gt; because, &lt;code&gt;si&lt;/code&gt; steps one instruction at a time, so to go through the function prologue we have to do it thrice.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, to see the function arguments we will again use the &lt;code&gt;info&lt;/code&gt; command. This time with &lt;code&gt;args&lt;/code&gt;. So perform &lt;code&gt;info args&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;
&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mh"&gt;0xa&lt;/span&gt;
&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;
&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you know the name of the function argument then we can use the &lt;code&gt;print&lt;/code&gt; command to print the value of that argument as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Program Stack
&lt;/h2&gt;

&lt;p&gt;Since, we are inside the function &lt;code&gt;factorial()&lt;/code&gt; which was called from &lt;code&gt;main()&lt;/code&gt; so if we return from &lt;code&gt;factorial()&lt;/code&gt; we will be back in &lt;code&gt;main()&lt;/code&gt;. For a simple program like this, it's not much of a big deal to remember which function is called by whom. But for a large codebase, it becomes difficult to keep track of it. So we have a command called &lt;code&gt;backtrace&lt;/code&gt; that shows us exactly this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="n"&gt;gef&lt;/span&gt; &lt;span class="n"&gt;backtrace&lt;/span&gt;
&lt;span class="cp"&gt;#0 factorial (n=0xa) at main.c:6
#1 0x00005555555551b2 in main () at main.c:17
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This very clearly tells us that we left &lt;code&gt;main()&lt;/code&gt; on line 17 and now we are in &lt;code&gt;factorial()&lt;/code&gt; on line 6.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cheatsheet
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;gdb program&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;to load the symbol table of the program and run the debugger&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;break &amp;lt;function name&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;to set a breakpoint at a function&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;break *&amp;lt;address&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;to set a breakpoint at a specific address&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;info break&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;to see the list of all the breakpoints&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;delete break &amp;lt;index&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;to delete a breakpoint&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;disable break &amp;lt;index&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;to disable a breakpoint&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ignore &amp;lt;index&amp;gt; &amp;lt;count&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;to ignore a breakpoint for count number of times&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;run &amp;lt;arglist&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;start your program with arglist&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;continue&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;continue the program execution&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;next&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;to execute the next line, including function calls&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;stepi&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;to step into the next machine instruction&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;info address &amp;lt;symbol-name&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;show where symbol s is stored&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;info func &amp;lt;regex&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;show names, types of defined functions (all, or matching regex)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;info var &amp;lt;regex&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;show names, types of global variables (all,or matching regex)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;info locals&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;show names, types of local variables&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;info args&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;show names, types of function arguments&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;whatis &amp;lt;expr&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;show data type of expr&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;p/&amp;lt;format&amp;gt; &amp;lt;expr&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;print the value of expr in the specified format&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;backtrace&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;show the call stack&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Final Notes
&lt;/h2&gt;

&lt;p&gt;Even though there is still a lot more to cover this article should give a basic understanding of how the debugger GDB works. If you are working with a large codebase you will have no option but to use debuggers like GDB. If properly used, these tools make your life a lot easier.&lt;/p&gt;

&lt;p&gt;Also, if you are a CTF player you might have come across Binary Exploitation challenges where again the only way to get the flag is by debugging the code and understanding the binary. There are more to GDB, like looking up the registers, finding a variable in a stack, watchpoints, threads, etc but those will be covered in later articles.&lt;/p&gt;




&lt;p&gt;I am a college undergrad who is constantly learning. If you have any feedback feel free to put it in the comments. I would really appreciate that. Also, feel free to contact me through any of these social handles (mainly active on Twitter):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://twitter.com/ArnabSen1729" rel="noopener noreferrer"&gt;Twitter @ArnabSen1729&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/arnabsen1729/" rel="noopener noreferrer"&gt;LinkedIn arnabsen1729&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/arnabsen1729" rel="noopener noreferrer"&gt;Github arnabsen1729&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="//arnabsen1729@gmail.com"&gt;Gmail&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://peerlist.io/arnabsen" rel="noopener noreferrer"&gt;Peerlist.io&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://arnabsen.bio.link/" rel="noopener noreferrer"&gt;arnabsen.bio.link&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Merkle Trees and its role in the decentralized web</title>
      <dc:creator>Arnab Sen</dc:creator>
      <pubDate>Wed, 17 May 2023 11:30:00 +0000</pubDate>
      <link>https://dev.to/arnabsen1729/merkle-trees-and-its-role-in-the-decentralized-web-2c00</link>
      <guid>https://dev.to/arnabsen1729/merkle-trees-and-its-role-in-the-decentralized-web-2c00</guid>
      <description>&lt;h2&gt;
  
  
  Centralised Web
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;How does the web in general work?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Usually, we have a server where we upload files, and then we can access those files from some other nodes connected to the network the server is connected to.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For example&lt;/em&gt;, if you want to host your videos for people to watch, you would rather choose Youtube or Google Drive or similar hosting/file-sharing services. Now, this is very convenient because a user doesn't have to maintain those services or manage them. But it comes at a cost. &lt;em&gt;The data is now concentrated on the infrastructure of a handful of providers.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gzCLJ_-H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1642441267020/A9j-0N0vo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gzCLJ_-H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1642441267020/A9j-0N0vo.png" alt="centralized.png" width="800" height="474"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Content Addressing
&lt;/h2&gt;

&lt;p&gt;But we can avoid this if we use a &lt;strong&gt;peer-2-peer system&lt;/strong&gt; , with the help of content addressing. Before diving into how the p2p system avoids decentralization let's first understand &lt;strong&gt;content addressing&lt;/strong&gt;. So, depending on the value of the content we can generate an address. We can use a cryptographic hash function. One of the popular functions is the &lt;code&gt;SHA-256&lt;/code&gt;. In your terminal, you can write this command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sha256sum file # will generate the SHA-256 hash of the file.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now even if you make a very small change, the sha256 value of the file will change drastically.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EEIY-xi3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1642441276703/ub-1jNIS8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EEIY-xi3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1642441276703/ub-1jNIS8.png" alt="terminal.png" width="800" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the output of this function (usually known as &lt;em&gt;hash&lt;/em&gt; or &lt;em&gt;digest&lt;/em&gt;) is of a fixed length. In the case of &lt;code&gt;SHA-256&lt;/code&gt;, it's &lt;code&gt;32 bytes&lt;/code&gt;. Also for each unique data, we will get a unique hash value. Thereby we can use the hash value for integrity check. As an analogy, if Alice and Bob are two different persons then quite naturally they will have different home addresses (not considering the exceptional cases, where Alice and Bob are roommates). So the home address in a way plays the role of identification for Alice and Bob. Similarly, the hash value plays the role of an address of the content (or data).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The exceptional case where Alice and Bob are roommates is actually analogous to something called &lt;strong&gt;Hash Collision&lt;/strong&gt;. Where two different values give the same hash, but it is very rare. So far no one has been able to find such values which give the same sha256 hash.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Peer to Peer Network
&lt;/h2&gt;

&lt;p&gt;Coming back to the peer-to-peer network. Instead of keeping the data in one server, we can share the data across multiple nodes (computers connected to the network are called &lt;strong&gt;nodes&lt;/strong&gt; ).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_Du_pM37--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1642441289142/8Se4gnczB.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_Du_pM37--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1642441289142/8Se4gnczB.png" alt="p2p.png" width="800" height="508"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now what are the pros:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It requires &lt;em&gt;less disk space&lt;/em&gt; since the data is now shared among multiple peers.&lt;/li&gt;
&lt;li&gt;If one node gets destroyed/tampered with the data can still be retrieved from the other node. Hence, no &lt;strong&gt;single-point-of-failure&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;But there are some cons as well. Participants in a peer to peer cannot be trusted. So when we retrieve a file we have to ensure that it is in good condition and is not tampered with or it is not malicious. But how can we do that in an efficient manner? This is where &lt;strong&gt;Merkle Trees&lt;/strong&gt; come into play.&lt;/p&gt;

&lt;h2&gt;
  
  
  Merkle Trees
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Merkle trees are a data structure that allows us to do efficient data verification across networks. It is a binary tree where the nodes store hashes instead of chunks of data.&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Merkle trees are named after &lt;strong&gt;Ralph Merkle&lt;/strong&gt; , who proposed them in a 1987 paper titled &lt;em&gt;"A Digital Signature Based on a Conventional Encryption Function."&lt;/em&gt; Merkle also invented cryptographic hashing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The leaf nodes store the hashes of the chunks of the data. And their parent nodes store the hash of concatenating the hashes of left child and right child.&lt;/p&gt;

&lt;p&gt;So, if we have 4 chunks of data. We first hash each one of them and get &lt;code&gt;Hash 1&lt;/code&gt;, &lt;code&gt;Hash 2&lt;/code&gt;, &lt;code&gt;Hash 3&lt;/code&gt;, &lt;code&gt;Hash 4&lt;/code&gt;. Now we concatenate &lt;code&gt;Hash 1&lt;/code&gt; and &lt;code&gt;Hash 2&lt;/code&gt; and then calculate the hash of that concatenated string. That is stored in &lt;code&gt;B1&lt;/code&gt; (Branch 1), similarly for &lt;code&gt;Hash 3&lt;/code&gt; and &lt;code&gt;Hash 4&lt;/code&gt;. We will keep doing this until we come to a single node in the tree which is called the root.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iU36Nw2Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1642441302256/zs_S0UgDK2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iU36Nw2Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1642441302256/zs_S0UgDK2.png" alt="tree1.png" width="800" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The root node has a special name in a Merkle Tree, we call it the &lt;strong&gt;Root Hash&lt;/strong&gt;. And actually plays a big role in p2p networks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Checking Equality
&lt;/h3&gt;

&lt;p&gt;Checking for equality becomes easy with Merkle Tree. &lt;em&gt;Why?&lt;/em&gt; Let's say one of the leaves has different data (unintended/tampered data). Now the hash for the corresponding leaf will be different. As a result, the parent hash will also be different and so on till the root. So if any data is tampered with, the root hash will give us different values.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kHJ8oE6G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1642441313243/4khT9v1Rr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kHJ8oE6G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1642441313243/4khT9v1Rr.png" alt="tree2.png" width="800" height="286"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So a change in any leaf node will be bubbled to the root hash. Now that reduces the comparisons we need to make to check the equality. And all we need to send to verify the data is the root hash, which is just 256 bits (or 32 bytes).&lt;/p&gt;

&lt;p&gt;This ease of verification plays a big role in the p2p network because all the peers are anonymous and are untrusted.&lt;/p&gt;

&lt;p&gt;Now, let's say you are supposed to download a file from your peers. And you already have the root hash of the file you were supposed to get. You download the data from your peers. What you can now do is build the Merkle Tree and calculate the Root Hash and check if the calculated Root Hash matches with the one you are expecting. If it matches then we are 100% sure that the data wasn't accidentally corrupted or intentionally tampered with. If it doesn't match then the data is tampered with or it is malicious.&lt;/p&gt;

&lt;h3&gt;
  
  
  Partial Verification
&lt;/h3&gt;

&lt;p&gt;But why shall we go all the way to make a Merkle Tree and not just concatenate all the data and calculate the hash? The reason is &lt;strong&gt;partial verification&lt;/strong&gt;. Sometimes we don't need the entire data set, only a couple of files are enough. We cannot verify that using the naive approach where we concatenated all the chunks of data and calculated the hash. But with the help of Merkle Trees, we can do it efficiently.&lt;/p&gt;

&lt;p&gt;Let's say we have 4 chunks of data. Before uploading to the p2p network I create a Merkle tree and find the root hash.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xr7Cqghq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1642441324673/_AiQuh97K.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xr7Cqghq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1642441324673/_AiQuh97K.png" alt="partial.png" width="800" height="631"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have saved the root hash safely. Now let's say we need Data 4. And one node says that it has the data. But how do we ensure that the data is not malicious? First, we will get Data 4, so we can just hash it and get Hash 4. Then we will need Hash 3 (remember not Data 3, just the hash). Using Hash 4 and Hash 3 we can calculate hash B2. Then we will need B1 and using B2 and B1 we can calculate root hash, which we already have. So we can easily compare them. So what information did we need?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Data 4 (the chunk of data we need)&lt;/li&gt;
&lt;li&gt;Hash 3&lt;/li&gt;
&lt;li&gt;B2&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ArPP3eqk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1642441333692/7MAluCKbK.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ArPP3eqk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1642441333692/7MAluCKbK.png" alt="partial2.png" width="719" height="747"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it. For a bigger tree, we will just need one data and a couple of hashes. The hashes have a fixed size of 32 bytes, so it will save a lot of bandwidth. Also, the number of hashes will be logarithmic to the number of leaves i.e chunks of data. &lt;em&gt;This way Merkle Trees can ease the verification process.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Use cases
&lt;/h2&gt;

&lt;p&gt;Merkle Trees are extensively used in Git, Bitcoin, and many other places. In Bitcoin specifically, it is used to validate transactions in a block. You can read more about it in the book &lt;a href="http://rosenbaum.se/book/grokking-bitcoin.html#merkle-trees"&gt;Grokking Bitcoin by Kalle Rosenbaum Section 6.5&lt;/a&gt;, the partial verification of Merkle Trees is used to check if a Transaction exists in a block.&lt;/p&gt;

&lt;p&gt;Gaurav Sen has also explained the same concept by taking the case of Git. You can watch the video &lt;a href="https://www.youtube.com/watch?v=qHMLy5JjbjQ"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/qHMLy5JjbjQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;




&lt;p&gt;I was a part of the &lt;a href="https://summerofbitcoin.org/"&gt;Summer of Bitcoin'21&lt;/a&gt; when I came across the concept of Merkle Trees and understood the important role it plays in Bitcoin and Blockchain. I would like to thank &lt;a href="https://twitter.com/kallerosenbaum"&gt;Kalle&lt;/a&gt; for explaining these concepts so beautifully. If you are new to bitcoin you should definitely check out his book &lt;a href="https://www.manning.com/books/grokking-bitcoin"&gt;Grokking Bitcoin&lt;/a&gt;. I am also grateful to &lt;a href="https://twitter.com/adibitcoin"&gt;Adi Shankara&lt;/a&gt;, &lt;a href="https://twitter.com/Caralie_C"&gt;Caralie Chrisco&lt;/a&gt;, &lt;a href="https://twitter.com/adamcjonas"&gt;Adam Jonas&lt;/a&gt; for giving us this amazing opportunity.&lt;/p&gt;

</description>
      <category>bitcoin</category>
      <category>blockchain</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Google I/O 2023 Highlights: Unveiling Google's Latest Innovations and Improvements</title>
      <dc:creator>Arnab Sen</dc:creator>
      <pubDate>Fri, 12 May 2023 06:29:55 +0000</pubDate>
      <link>https://dev.to/arnabsen1729/google-io-2023-highlights-unveiling-googles-latest-innovations-and-improvements-34nn</link>
      <guid>https://dev.to/arnabsen1729/google-io-2023-highlights-unveiling-googles-latest-innovations-and-improvements-34nn</guid>
      <description>&lt;p&gt;In this blog, I will cover all the latest developments happening within Google, as presented at Google I/O. I won't delve deeply into the workings and technology, as that would make the blog excessively long. Instead, I will provide an overview of the topics discussed and explain them as concisely as possible.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I will mainly cover the new software developments in the field of AI and not the hardware and android updates.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;Google I/O 2023 showcased AI advancements such as LaMDA, PaLM2, Imagen, and new AI features in Google Search. They also introduced AI integrations in products like Gmail, Google Maps, and Google Photos, along with the launch of Bard, an AI chatbot. Other announcements include AI tools for developers like Vertex AI and Project Tailwind, an AI-first notebook.&lt;/p&gt;

&lt;p&gt;Let's learn what Google I/O is all about.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is "Google I/O"?
&lt;/h2&gt;

&lt;p&gt;Google I/O is an annual developer conference held by Google in Mountain View, California. The name "I/O" is taken from the number &lt;strong&gt;googol&lt;/strong&gt; , with the "I" representing the &lt;code&gt;1&lt;/code&gt; in googol and the "O" represents the first &lt;code&gt;0&lt;/code&gt; in the number.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A &lt;strong&gt;googol&lt;/strong&gt; is the large number &lt;strong&gt;10&lt;sup&gt;100&lt;/sup&gt;&lt;/strong&gt;. In decimal notation, it is written as the digit 1 followed by one hundred zeroes: &lt;strong&gt;10,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The conference also features a number of educational sessions and workshops, where developers can learn about the latest technologies and best practices.&lt;/p&gt;

&lt;p&gt;In addition to being a valuable resource for developers, Google I/O is also a great opportunity for Google to connect with its users and get feedback on its products. The conference is open to the public, and there are a number of activities and events that are available to all attendees.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Google I/O 2023&lt;/strong&gt; was a two-day event held on &lt;strong&gt;May 11-12, 2023&lt;/strong&gt; , at the Shoreline Amphitheatre in &lt;strong&gt;Mountain View, California&lt;/strong&gt;. The event was attended by over &lt;strong&gt;50,000&lt;/strong&gt; developers from around the world.&lt;/p&gt;

&lt;p&gt;A keynote was addressed by &lt;strong&gt;Sundar Pichai&lt;/strong&gt; , CEO of Google, where he announced new products and features for Google's various platforms.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ij_TT28k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://storage.googleapis.com/gweb-uniblog-publish-prod/images/hero-1.width-1200.format-webp.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ij_TT28k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://storage.googleapis.com/gweb-uniblog-publish-prod/images/hero-1.width-1200.format-webp.webp" alt="Sundar Pichai at the front left of a large stage with a colorful I/O logo behind him." width="800" height="333"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  💡 What were my expectations from Google I/O 2023?
&lt;/h2&gt;

&lt;p&gt;We all know that Google has been a leader in the field of artificial intelligence (AI) for decades. In 2017, they released the revolutionary transformer model, which is now widely used in natural language processing (NLP) tasks such as machine translation, text summarization, and question-answering.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3AM0PD3---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1683818052782/1af441c4-65bc-4ed7-8517-839633384ae4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3AM0PD3---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1683818052782/1af441c4-65bc-4ed7-8517-839633384ae4.png" alt="" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can checkout the amazing paper by folks at Google titled "Attention is All You Need" from &lt;a href="https://arxiv.org/pdf/1706.03762.pdf"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It was therefore no surprise that Google's annual developer conference, Google I/O 2023, was full of announcements about new AI advancements.&lt;/p&gt;

&lt;p&gt;Some of the most notable announcements included:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The release of &lt;strong&gt;PaLM2&lt;/strong&gt; , a 540-billion parameter LLM that can generate text, translate languages, write different kinds of creative content, and answer your questions in an informative way.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The release of &lt;strong&gt;Imagen&lt;/strong&gt; , a new AI model that can generate realistic images from text descriptions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The announcement of new AI features for &lt;strong&gt;Google Search&lt;/strong&gt; , including the ability to answer your questions in more natural language and to provide more relevant results.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The launch of new &lt;strong&gt;AI tools for developers&lt;/strong&gt; , including the Google AI Platform and the Google AI Test Kitchen.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are just a few of the many AI advancements that were announced at Google I/O 2023. It is clear that Google is committed to leading the way in the field of AI, and these advancements are sure to have a significant impact on the way we live and work.&lt;/p&gt;

&lt;p&gt;A significant part of Google I/O focused on integrating Generative AI into their products. So, what exactly is Generative AI?&lt;/p&gt;

&lt;h2&gt;
  
  
  🤖 Understanding Generative AI
&lt;/h2&gt;

&lt;p&gt;Generative AI as the name suggests is a type of artificial intelligence (AI) model called Large Language Model (LLM) that &lt;strong&gt;can create new content&lt;/strong&gt; , such as text, images, audio, and video. Generative AI models are trained on large datasets of existing content, and they use this data to learn the patterns and rules that govern how that content is created. Once a generative AI model has been trained, it can use this knowledge to create new content that is similar to the content it was trained on.&lt;/p&gt;

&lt;p&gt;Here is a nice video on the recent updates in Generative AI by Google.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/628ANvH1jH0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  📲 AI integrations in Google products
&lt;/h2&gt;

&lt;h3&gt;
  
  
  📪 Gmail's new "Help me write"
&lt;/h3&gt;

&lt;p&gt;This AI feature will generate the entire email for you. All you have to do is specify the details of the email in the prompt. It can further pull context from the previous email.&lt;/p&gt;

&lt;p&gt;This is something I will personally use quite often. Currently, there are some excellent tools in the form of browser extensions built on OpenAI's GPT model that serve the same purpose. However, it appears that this new feature from Google could be detrimental to those tools.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtube.com/clip/Ugkxf9r4MA7Fztdkgzi6MjvJrh_Baz5ze8dt"&gt;https://youtube.com/clip/Ugkxf9r4MA7Fztdkgzi6MjvJrh_Baz5ze8dt&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  🌍 Immersive View for routes in Maps
&lt;/h3&gt;

&lt;p&gt;Google Maps' Immersive View is being expanded to allow users to see their entire route in advance, whether they're walking, cycling, or driving. This will allow users to get a better feel for their route and make informed decisions about where to go. Immersive View will begin to roll out over the summer and will be available in 15 cities by the end of the year.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtube.com/clip/UgkxcxMUAvh_dh2v1vf-QCk_W8bl2pf42mBb"&gt;https://youtube.com/clip/UgkxcxMUAvh_dh2v1vf-QCk_W8bl2pf42mBb&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Magic Eraser for Google Photos
&lt;/h3&gt;

&lt;p&gt;It is an AI-powered tool that allows users to remove unwanted distractions from photos. Magic Editor is a new AI-powered tool that will allow users to do much more with their photos, such as repositioning objects, changing the sky, and more. Magic Editor is expected to roll out later this year.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qVVwNZXa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://storage.googleapis.com/gweb-uniblog-publish-prod/original_images/I-0_MM_BALLOONS_Updated_Disclaimer.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qVVwNZXa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://storage.googleapis.com/gweb-uniblog-publish-prod/original_images/I-0_MM_BALLOONS_Updated_Disclaimer.gif" alt="https://blog.google/technology/ai/google-io-2023-keynote-sundar-pichai/#helpful-ai" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The second-gen PaLM model: PaLM 2
&lt;/h2&gt;

&lt;p&gt;PaLM is a large language model (LLM) from Google AI, but it is not the only LLM that Google has developed. Other LLMs from Google include LaMDA, Meena, and T5. PaLM is the largest and most powerful LLM that Google has developed to date, but it is still under development.&lt;/p&gt;

&lt;p&gt;And in this I/O, Google announced a more advanced version of that called PaLM2.&lt;br&gt;&lt;br&gt;
PaLM2 is a second-generation large language model (LLM) from Google AI. It is built on the same architecture as PaLM, but it is trained on a larger dataset of text and code.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/yAANQypgOo8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;PaLM2 is a family of models, each with its own strengths and weaknesses. Here are some of the different models in PaLM2:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0ekMZsEg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1683825768659/c6df367f-3fd0-4080-b568-506fefe6e31c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0ekMZsEg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1683825768659/c6df367f-3fd0-4080-b568-506fefe6e31c.png" alt="" width="800" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Gecko:&lt;/strong&gt; Gecko is the smallest model in PaLM2. It is fast and efficient, but it is not as powerful as the other models.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Otter:&lt;/strong&gt; Otter is a medium-sized model in PaLM2. It is more powerful than Gecko, but it is not as powerful as the larger models.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bison:&lt;/strong&gt; Bison is a large model in PaLM2. It is more powerful than Otter, but it is not as powerful as the largest model.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Unicorn:&lt;/strong&gt; Unicorn is the largest model in PaLM2. It is the most powerful model in PaLM2, but it is also the slowest and least efficient.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;PaLM2 is particularly good at:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Math:&lt;/strong&gt; It can solve math problems, such as algebra, calculus, and geometry. It can also generate mathematical proofs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Coding:&lt;/strong&gt; PaLM2 can generate code that is both correct and efficient. It can write code in a variety of programming languages, and translate between them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Learning &amp;amp; Reasoning:&lt;/strong&gt; PaLM2 is able to learn new tasks and concepts quickly. It can be trained on a new task with just a few examples.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Translating languages:&lt;/strong&gt; PaLM2 can translate languages with high accuracy. It can translate between any pair of languages that it has been trained on.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;PaLM2 models perform even better when fine-tuned for particular applications. Some of my favorite fine-tuned models are Sec-PaLM and Med-PaLM2. Sec-PaLM can explain the behavior of potentially malicious scripts, and better detect which scripts are actually threats to people and organizations. Med-PaML2 can answer questions and summarize insights from a variety of dense medical texts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BNPf9zMz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1683826123107/4007da7c-6efa-4183-bd2e-661f5f1007d5.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BNPf9zMz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1683826123107/4007da7c-6efa-4183-bd2e-661f5f1007d5.gif" alt="Med-PaLM2 demo" width="640" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Google is also working on another next-generation foundation model called &lt;strong&gt;Gemini.&lt;/strong&gt; Gemini is being designed to be multimodal, which means that it will be able to process and understand information from a variety of sources, such as text, code, images, and audio. This will make Gemini much more versatile than previous AI models, and it will allow it to be used in a wider range of applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  💬 Bard
&lt;/h2&gt;

&lt;p&gt;The part of Google I/O that I was most excited about was the launch of Bard. It was initially rolled out to only US and UK, but now it's publicly available and I am really loving it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9MdDtM4P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1683827214728/e082c306-431c-4e09-81b2-7c99ab366904.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9MdDtM4P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1683827214728/e082c306-431c-4e09-81b2-7c99ab366904.png" alt="Bard searching weblinks" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A very popular alternative that we all know is ChatGPT. Here are some of the features that Bard is providing which is not yet available in ChatGPT:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Information Cutoff:&lt;/strong&gt; The information cutoff for ChatGPT is September 2021. Whereas Bard can perform an internet search and give a response accordingly. This allows you to get the latest information and updates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Export options:&lt;/strong&gt; Bard allows you to export the response as Docs or a Draft in Gmail. If it detects code then it also gives an option to "Export to Colab" but ChatGPT doesn't have any such functionality yet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Citations:&lt;/strong&gt; Bard can also cite sources, something which ChatGPT still can't do.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Further, Google is promising that in the next few weeks, Bard will become more visual. Bard will also be integrated with Google Lens, where it can analyze the photos and then respond according to your prompt.&lt;/p&gt;

&lt;h3&gt;
  
  
  🎨 Bard x Adobe Firefly
&lt;/h3&gt;

&lt;p&gt;This collaboration will allow Bard users to generate images directly from their text descriptions, using Firefly's state-of-the-art technology.&lt;/p&gt;

&lt;p&gt;To use this feature, Bard users will simply need to type a description of the image they want to generate into the chatbot. Firefly will then use its AI to create an image that matches the description. Users will be able to edit the image as needed, and they can even share it directly on social media.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--leunmCJE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://storage.googleapis.com/gweb-uniblog-publish-prod/original_images/Bard_Demo_03_Image_Generation_v10_.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--leunmCJE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://storage.googleapis.com/gweb-uniblog-publish-prod/original_images/Bard_Demo_03_Image_Generation_v10_.gif" alt="Bard prompt asking to create an image of a unicorn with birthday cake" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  💼 Workspaces
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X6uA47fk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1683830425929/8d2cd0b1-6ee8-43b9-9374-05da08c64299.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X6uA47fk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1683830425929/8d2cd0b1-6ee8-43b9-9374-05da08c64299.png" alt="Google Workspaces" width="800" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Some of the popular tools available in Google Workspaces like Docs, and Sheets will have options for users to prompt specific requirements. From generating job descriptions, and creating tables with data inserted, to creating images with specific styles everything can be done with just a simple prompt directly from these tools. You can do these with a side panel called "sidekick" which will keep track of the context and then provide relevant information. This will make prompting very easy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Fs92Drcd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1683830922641/287d624f-991e-4a05-b60c-5d84c70d7fc6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Fs92Drcd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1683830922641/287d624f-991e-4a05-b60c-5d84c70d7fc6.png" alt="Sidekick in Google Docs" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All of this will be generally available to business and consumer Workspace users later this year via a new service called &lt;strong&gt;Duet AI&lt;/strong&gt; for Workspace.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔍 Generative AI in Search
&lt;/h2&gt;

&lt;p&gt;A typical Google Search can be quite challenging, to be honest. To obtain very specific information, you must break down the text you are searching for and then skim through the results to find the precise answer.&lt;/p&gt;

&lt;p&gt;But with this new integration of Generative AI, you don't have to do so anymore. It will automatically take care of extracting the information, getting relevant results and then compiling the results to give you the perfect response.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IGLXjWvO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1683864157787/10c3205b-0081-447a-9c89-73487e6194d5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IGLXjWvO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1683864157787/10c3205b-0081-447a-9c89-73487e6194d5.png" alt="Demo of Generative AI" width="800" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Vertex AI
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RX0SpyZs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/v2/resize:fit:549/1%2Ag-YZo7s0j46lDQfMmQ955A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RX0SpyZs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/v2/resize:fit:549/1%2Ag-YZo7s0j46lDQfMmQ955A.png" alt="Vertex AI logo" width="549" height="348"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Vertex AI is a managed machine learning (ML) platform that helps you build, deploy, and scale ML models. It offers a unified experience for managing the entire ML lifecycle, from data preparation to model training and deployment. Vertex AI also provides a variety of tools and services to help you accelerate your ML projects.&lt;/p&gt;

&lt;p&gt;Other big techs are already availing this functionality in their apps, like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;replit&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Uber&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Canva&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;character.ai&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Vertex has the support of 3 new models, in addition to PaLM2.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Imagen:&lt;/strong&gt; which powers image generation, editing, and customization from text inputs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Codey:&lt;/strong&gt; for code completion and generation, which can be trained on code base to help build applications faster.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Chirp:&lt;/strong&gt; universal speech model which brings speech-to-text accuracy for over 300 languages.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All of these features are already in Preview and can be used.&lt;/p&gt;

&lt;h2&gt;
  
  
  📔 Project Tailwind
&lt;/h2&gt;

&lt;p&gt;Project Tailwind is an experimental AI-first notebook that learns from your documents and helps you learn faster. You can upload the docs using Google Drive and that creates a custom fine-tuned model for you to interact with.&lt;/p&gt;

&lt;p&gt;It can be used:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;to create study guides&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;find sources&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;generate quizzes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;do a quick Google search to get more information.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--k1zUjVNC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1683868215514/593378d7-0e8c-4930-bbfe-b12fd0129178.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k1zUjVNC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1683868215514/593378d7-0e8c-4930-bbfe-b12fd0129178.png" alt="Project Tailwind Demo" width="800" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Google I/O 2023 unveiled groundbreaking AI advancements and integrations, showcasing the power of AI to revolutionize the way we live, work, and interact with technology. These innovations promise to make our lives more efficient, connected, and inspired as we move toward a brighter future.&lt;/p&gt;

&lt;p&gt;As we embrace the future of AI, let's harness its power to innovate, improve our lives, and create a world where technology is a catalyst for positive change, empowering us to reach new heights and achieve our greatest potential.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://blog.google/technology/ai/google-io-2023-keynote-sundar-pichai/"&gt;Google I/O 2023: Keynote&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://blog.google/technology/ai/google-palm-2-ai-large-language-model/"&gt;Introducing PaLM 2&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;If you found this blog useful, do leave a comment and like this blog, it really motivates me to put forward more such content. You can follow me on Twitter for further updates. My Twitter handle: &lt;a href="https://twitter.com/ArnabSen1729"&gt;@ArnabSen1729&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can find the rest of my social links at &lt;a href="https://arnabsen.dev/links"&gt;arnabsen.dev/links&lt;/a&gt;. Thank you and have a wonderful day.&lt;/p&gt;

</description>
      <category>google</category>
      <category>devrel</category>
      <category>techtalks</category>
    </item>
    <item>
      <title>Landing a Google SWE Internship: Interview Experience and preparation journey</title>
      <dc:creator>Arnab Sen</dc:creator>
      <pubDate>Tue, 04 Apr 2023 19:14:00 +0000</pubDate>
      <link>https://dev.to/arnabsen1729/landing-a-google-swe-internship-interview-experience-and-preparation-journey-2noi</link>
      <guid>https://dev.to/arnabsen1729/landing-a-google-swe-internship-interview-experience-and-preparation-journey-2noi</guid>
      <description>&lt;p&gt;Even though, there is a plethora of articles on Google SWE Internship interview experience online, I am still frequently asked the following questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How did you crack Google SWE Internship?&lt;/li&gt;
&lt;li&gt;Which resources did you follow?&lt;/li&gt;
&lt;li&gt;Can you share some interview tips for my upcoming interview?&lt;/li&gt;
&lt;li&gt;Was it on-campus or off-campus?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;... and many more. So, I decided to pen down my thoughts so that I can share this article next time someone asks me anything about my SWE Internship.&lt;/p&gt;

&lt;h2&gt;
  
  
  What can you expect from this blog?
&lt;/h2&gt;

&lt;p&gt;These are the few things that I would like to cover in this blog&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How I optimized my resume.&lt;/li&gt;
&lt;li&gt;How I approached (or, usually approach) referrals.&lt;/li&gt;
&lt;li&gt;Resources I referred to while preparing for DSA.&lt;/li&gt;
&lt;li&gt;Interview tips&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTE: Although this article is about Google, the recommendations will be useful if you apply to other product-based companies.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Hi, I am Arnab Sen, a Software Developer from India 🇮🇳. I interned at Google as an SWE for the summer of 2022 and even grabbed a Pre-Placement Opportunity. I will join Google India as a Full Time, in July 2023. When I was in my third year Google, unfortunately, didn't visit our campus. So I had to take the off-campus route to land at Google and here is my journey:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--c1cf2plh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://arnabsen.dev/images/landing-google-swe-internship/setup.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--c1cf2plh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://arnabsen.dev/images/landing-google-swe-internship/setup.jpeg" alt="My Google Internship Setup" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Decoding the Google Application Process
&lt;/h2&gt;

&lt;p&gt;Let's understand how Google usually hires candidates for the Software Engineering Role:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Resume Shortlisting&lt;/li&gt;
&lt;li&gt;Online Aptitude Round&lt;/li&gt;
&lt;li&gt;Telephonic Round&lt;/li&gt;
&lt;li&gt;Technical Interviews&lt;/li&gt;
&lt;li&gt;Hiring Committee&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I'll go through each round and talk about what happened and how I prepared.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The same rounds are usually followed by most of the Product based companies like Microsoft, Amazon, Meta .etc.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Round 1: Resume Shortlisting
&lt;/h2&gt;

&lt;p&gt;It was in Aug 2021 that I came across the Google India SWE Intern opening in &lt;a href="https://careers.google.com/jobs"&gt;Google's career portal&lt;/a&gt; and I applied with a referral from one of my seniors.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resume building tips
&lt;/h3&gt;

&lt;p&gt;Your resume is the first thing that creates an impression. Even if you are super talented and skilled, a poor resume can negate all your abilities. So, you need to create a kickass resume that showcases your talents and impresses everyone!&lt;/p&gt;

&lt;p&gt;Originally I used to create my resume in &lt;strong&gt;LaTeX&lt;/strong&gt; but later on, it became a hassle to maintain and make updates. Hence I moved on to this website called &lt;a href="https://flowcv.com/"&gt;flowcv.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Their interface is &lt;strong&gt;user-friendly&lt;/strong&gt; and offers &lt;strong&gt;pre-defined templates&lt;/strong&gt; while allowing ample options for personalizing your resume. Check out the template I personally used.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9igQe83w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/naam4og46ei12qzmxuqf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9igQe83w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/naam4og46ei12qzmxuqf.png" alt="I used the right most template to create my resume" width="800" height="367"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I prefer a &lt;strong&gt;single-column&lt;/strong&gt; resume. If you want to stick to &lt;strong&gt;LaTeX&lt;/strong&gt; and you are looking for a resume template, my suggestion would be to use &lt;a href="https://www.overleaf.com/latex/templates/deedy-cv/bjryvfsjdyxz"&gt;DeedyCV&lt;/a&gt;. It looks very professional and compact.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7bLesi17--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/frw94aubnyj337rj8gmg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7bLesi17--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/frw94aubnyj337rj8gmg.png" alt="Deedy CV" width="553" height="715"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Resume tips to keep in mind
&lt;/h3&gt;

&lt;p&gt;Here are some of my tips for your resume:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If you wanna look like a pro, make sure your stuff &lt;strong&gt;doesn't have any spelling or grammar mistakes&lt;/strong&gt;. You can use tools like Google Docs spelling check or Grammarly to help you out.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Just get &lt;strong&gt;straight to the point&lt;/strong&gt; and don't use fancy words. Nobody cares about your language skills, they just want to know what you can do as a developer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It would be great if you could &lt;strong&gt;add some proof to your work&lt;/strong&gt;. If you have built a project, published a paper, or completed a certification, you must provide a link for the respective work.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Don't stuff everything&lt;/strong&gt; into one page of your resume. Leave some space to breathe. It's totally fine to use 2 pages if you need to. I checked with some Google peeps and recruiters and they all said it's all good to have a 2-page resume if one page just ain't cutting it.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, let me share with you some hacks that can use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;If you don't have achievements&lt;/strong&gt;, try to take part in Leetcode, GFG, Hackerrank, or HackerEarth contests or contests of college fests. You can put those ranks in your achievements. To know the upcoming contests, check out &lt;a href="https://clist.by/"&gt;clist.by&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;If you don't have projects&lt;/strong&gt;, try to take part in hackathons with your peers. "I can't think of a good project" is what I hear from a lot of my juniors. Right now, if I ask you to think of anything, you won't be thinking of anything. But if I asked you to think of a fruit, you might be thinking of a banana, apple, mango, etc. Every hackathon has a unique theme, so by the end of the hackathon you will have a somewhat unique project. You can find such hackathons at &lt;a href="https://devpost.com/"&gt;Devpost&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;If you don't have enough work experience&lt;/strong&gt;, pick up a good open-source project from GitHub and try to make contributions to that for like 1-2 months. By the end of it, you will have enough experience and contributions that you can put it under the "Open Source Experience" category.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are interested to know what my resume looks like, check out: &lt;a href="https://arnabsen.dev/resume"&gt;arnabsen.dev/resume&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Elevate your referral game
&lt;/h3&gt;

&lt;p&gt;Companies like Google actually let their own employees refer potential candidates. Although a referral doesn't &lt;strong&gt;necessarily guarantee you a job&lt;/strong&gt; offer, it does mean your &lt;strong&gt;application will stand out&lt;/strong&gt; from the rest of the applicants, which can only mean one thing - your chances of getting hired just got a whole lot higher. In some cases, a &lt;strong&gt;Good Resume + Referral&lt;/strong&gt; can fast forward in the application rounds. In my case, I was directly skipped to the Technical Interview rounds.&lt;/p&gt;

&lt;p&gt;Now few things to keep in mind:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The number of referrals doesn't matter.&lt;/strong&gt; It's the quality of the referral that makes the difference. I'm familiar with Google's internal referral portal. Employees must respond to questions such as, why do you believe this candidate is a good fit, have you previously worked with the candidate, and so on. Hence, if the person referring you understands your strengths and weaknesses, the referral will be stronger, and your chances will be better.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I was lucky enough to have a senior in my college who was ready to refer me. We knew each other since day 1 of my college so he was able to write a good referral for me. Shoutout to &lt;a href="https://www.linkedin.com/in/surikumkaran/"&gt;Suryansh Gupta&lt;/a&gt;. So you can always reach out to your seniors regarding referrals.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you don't have such seniors in your college, no worries, you can get referrals over &lt;strong&gt;LinkedIn&lt;/strong&gt;, &lt;strong&gt;Twitter&lt;/strong&gt;, etc. When asking for referrals make sure you provide all the necessary information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;job id&lt;/strong&gt; of the role you are applying for.&lt;/li&gt;
&lt;li&gt;Your &lt;strong&gt;resume&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Your &lt;strong&gt;achievements&lt;/strong&gt; and &lt;strong&gt;relevant skills&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Why do you think you are a good fit for the role?&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;College tip: active interaction with seniors in your college can have a positive effect on your career. So, don't be shy.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, let's say your resume got shortlisted. Then what?&lt;/p&gt;

&lt;h2&gt;
  
  
  Round 2: Online Aptitude Round
&lt;/h2&gt;

&lt;p&gt;Even though I skipped the OA round, here are some preparation tips:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Google usually asks pretty standard questions which are of the Leetcode Medium-Hard difficulty. So don't just solve easy questions. Also, no need to waste time by solving very difficult questions either.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make sure you know all the standard algorithms, I will share the list after this.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I also prepared by participating in Competitive Programming contests, especially from &lt;a href="https://atcoder.jp/"&gt;Atcoder&lt;/a&gt; and &lt;a href="https://leetcode.com"&gt;LeetCode&lt;/a&gt;. This was done to ensure that I could answer the questions swiftly and within the time limit, exactly like an actual OA.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My advice would be to go through the past OA rounds questions. Here is the list I referred to for Google's questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://leetcode.com/discuss/interview-question/352460/Google-Online-Assessment-Questions"&gt;https://leetcode.com/discuss/interview-question/352460/Google-Online-Assessment-Questions&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://algo.monster/problems/google_online_assessment_questions"&gt;https://algo.monster/problems/google_online_assessment_questions&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.codingninjas.com/codestudio/problem-lists/top-google-coding-interview-questions"&gt;https://www.codingninjas.com/codestudio/problem-lists/top-google-coding-interview-questions&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.interviewbit.com/google-interview-questions/"&gt;https://www.interviewbit.com/google-interview-questions/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can find similar collections of questions for other companies as well.&lt;/p&gt;

&lt;h3&gt;
  
  
  Standard topics to prepare for OAs
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Binary search&lt;/li&gt;
&lt;li&gt;BFS/DFS/Flood fill&lt;/li&gt;
&lt;li&gt;Tree traversals&lt;/li&gt;
&lt;li&gt;Hash tables&lt;/li&gt;
&lt;li&gt;Linked list, Stacks, Queues, Two pointers/Sliding window&lt;/li&gt;
&lt;li&gt;Binary heaps&lt;/li&gt;
&lt;li&gt;Dynamic programming&lt;/li&gt;
&lt;li&gt;Union find&lt;/li&gt;
&lt;li&gt;Ad hoc/string manipulations&lt;/li&gt;
&lt;li&gt;Trie &lt;em&gt;(good to know)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Segment trees/Fenwick trees &lt;em&gt;(good to know)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Bitmasks &lt;em&gt;(good to know)&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you are done with the OA you will be taken to the 3rd round.&lt;/p&gt;

&lt;h2&gt;
  
  
  Round 3: Telephonic Round
&lt;/h2&gt;

&lt;p&gt;So, for this round, they're gonna call you up and hit you with some theoretical Data Structures and Algorithms questions. Some might even have multiple-choice answers. They might throw in some programming language questions too. Here are some examples of questions that you can expect to get an idea:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What are the pros and cons of using an adjacency list over an adjacency matrix for a graph problem?&lt;/li&gt;
&lt;li&gt;What is the data structure used in a priority queue?&lt;/li&gt;
&lt;li&gt;What is the difference between Binary Search Tree and Heap?&lt;/li&gt;
&lt;li&gt;How is a C++ &lt;code&gt;map&lt;/code&gt; different from &lt;code&gt;unordered_map&lt;/code&gt; from an implementation point of view?&lt;/li&gt;
&lt;li&gt;Which algorithm would you use for a network flow problem?&lt;/li&gt;
&lt;li&gt;What are the time complexities of Bellman-Ford and Dijkstra's algorithm?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have a strong fundamental understanding of Data Structures and Algorithms then these won't be very difficult for you.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resources to study DSA
&lt;/h3&gt;

&lt;p&gt;I studied DSA mainly from these two sources:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://sd.blackball.lv/library/Introduction_to_Algorithms_Third_Edition_(2009).pdf"&gt;Introduction to Algorithm by CLRS (a.k.a the Bible of DSA)&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---6qaXy-E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hb83tqyhbgt8ipw1gimg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---6qaXy-E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hb83tqyhbgt8ipw1gimg.png" alt="CLRS" width="767" height="861"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/playlist?list=PLUl4u3cNGP61Oq3tWYp6V_F-5jb5L2iHb"&gt;MIT 6.006 Introduction to Algorithms, Fall 2011&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kJ1RLEAQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sa2014zez22hewruptnd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kJ1RLEAQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sa2014zez22hewruptnd.png" alt="MIT 6.006" width="800" height="585"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, I made sure to take notes while watching those videos and reading the book chapters. And when I got stuck with any problem, I just Googled it and checked out the first link - be it an article or a video.&lt;/p&gt;

&lt;p&gt;Once you complete the telephonic round you will be invited for the technical interview rounds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Round 4: Interview Rounds
&lt;/h2&gt;

&lt;p&gt;It was on &lt;strong&gt;13th September&lt;/strong&gt; I received a mail stating that I have my interview lined up after a week. I freaked out a little. Because first, I didn't expect to hear back from them. And second, how am I supposed to prepare for a Google interview in 7 days?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WflQCHCa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/706i93m5wxkodwvs86uo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WflQCHCa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/706i93m5wxkodwvs86uo.png" alt="Google India Software Internship" width="634" height="157"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I took a smart approach. I checked out other people's experiences with Google Interviews and saw that they like to ask about DP, Graphs, Binary Search, Lazy Sum, and Sliding Windows stuff. I went back and reviewed all the notes I took from that MIT course and honed in on those types of questions. I practiced topic-wise from LeetCode itself.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Another question I get is if LeetCode premium is really worth it. To be honest, in today's time it isn't anymore. There are tonnes of other platforms which have similar questions for free that are only available in LeetCode premium. But 2 years back, I felt spending Rs 10.5k for 1 year of LC premium might be worth it. Because if I am able to crack a job like Google, that amount invested will be just a fraction of the monthly salary. So, I got 1 year of LC premium.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  My style of practicing for interview
&lt;/h3&gt;

&lt;p&gt;After discussing with my seniors I realized that solving a question in an interview setting is completely different than practicing questions by myself. Most of these Google interviews happen on an editor-based portal where you cannot run the code and it also doesn't support intellisense. So, I would create a Google doc where I would solve all the questions and write code. This way I didn't have the privilege of syntax highlighting or intellisense. As they say, &lt;em&gt;"Hope for the best, Prepare for the worst".&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HFNDdjq_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7y8gtqa3spea46ll63rt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HFNDdjq_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7y8gtqa3spea46ll63rt.png" alt="Google Docs" width="800" height="606"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The strategy of breaking down Google interviews
&lt;/h3&gt;

&lt;p&gt;A Google Interview happens for 45 mins and they usually ask 2 questions. So, I divided the total time into (20 + 20 + 5) mins. 20 mins for each question and 5 mins as a buffer (for an emergency like network issues or Q&amp;amp;A at the end).&lt;/p&gt;

&lt;p&gt;Within those 20 mins, I would spend 3-5 mins understanding the question asking clarifying questions, and explaining my approach. 10 mins for implementing the optimized solution and 5 mins for dry running or debugging. Note that you have to come up with the optimal solution as quickly as possible. So, I would insist on not wasting time trying to implement the brute-force solution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OATMS8Qd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o1kodr8dbeb7it5dral5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OATMS8Qd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o1kodr8dbeb7it5dral5.png" alt="Breaking down Google Interviews" width="800" height="621"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, even during practice when I was solving the questions myself I followed the same strategy. I would pretend that I am in an interview setting. I would try to read my thoughts out loud and explain everything. I even made the habit of doing a dry run every time I wrote the final code for a problem.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mock Interviews are an absolute necessary
&lt;/h3&gt;

&lt;p&gt;To succeed in any field, preparation is key. Just as astronauts undergo rigorous training to prepare for the unique conditions of zero gravity, so too must job seekers prepare for the challenge of a job interview. One effective way to do this is by practicing mock interviews. That way you can know your weakness, and you can prepare for them before the actual interview.&lt;/p&gt;

&lt;p&gt;I also watched a lot of Mock Interview videos on Youtube to give me an idea of what it would be like during an interview setting. I created a playlist of all the videos that I referred to.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/playlist?list=PLeXWGmu4fYL76f_nnnGyCu9Tr9k5NYtko"&gt;Link to the playlist 📼.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JQanCpSl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zjsecoejd5imjehmhmgu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JQanCpSl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zjsecoejd5imjehmhmgu.png" alt="Mock Interview Playlist" width="800" height="553"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I gave a bunch of mock interviews (around 5-6) by taking the help of my seniors and using online free platforms like &lt;a href="https://www.pramp.com/invt/lYAEXB2Pa1Hxra4p3zMP"&gt;Pramp&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Importance of clarifying questions
&lt;/h3&gt;

&lt;p&gt;The initial question that will be given to you, will be intentionally very vague. They will expect you to ask some clarifying questions to identify the fine details of the question. Let's take a very simple example, you are given an array of n numbers, and you have to find the subarray with the maximum sum.&lt;/p&gt;

&lt;p&gt;Now, your first thought might be using Kandane's Algorithm. But wait, what if all the numbers are positive? In that case, the answer is simply the entire array. As you can see one small change in the constraints, had a big effect on the final solution. So always practice asking clarifying questions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Interview tips to keep in mind
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Treat the interview more like a conversation with a fellow software developer and not like a viva. This will also help you tackle your nervousness.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;During the interviews, you should also think about other ways to improve the solution. Share the different options or tradeoffs that you're considering.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Think out loud because that way the interviewer will know your thought process and can give you signals if you are going in the wrong direction.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Discuss tradeoffs if possible. How would you improve your solution? How do you make it faster? How to optimize the space complexity? Know the time and space tradeoffs of the solution/data structures that you are picking.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Try to avoid taking hints, but always remember solving with hints is much better than not solving at all.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Avoid syntactical errors like missing semicolons, not closing parenthesis, wrong indentation, etc. Even though they are not deal-breakers, writing high-quality code can showcase your skills as a developer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, use proper variable names and if required add meaningful comments. But remember you have limited time so just don't spend minutes trying to come up with an appropriate variable name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make it a habit to always calculate the Time and Space complexity of your solution.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;If you don't remember the exact syntax of a library class or method, that is fine. You can just let the interviewer know, and replace it with a meaningful substitute.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;All of these points might be hard to keep in mind during the interview, which is why the more mock interviews you give, the better you get at remembering these subtle points.&lt;/p&gt;

&lt;p&gt;Here are some more resources that I referred to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.bigocheatsheet.com/"&gt;Big-O-Cheatsheet&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For some last-minute revision, I also followed this collection of LC questions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://seanprashad.com/leetcode-patterns/"&gt;https://seanprashad.com/leetcode-patterns/&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  My interview experience
&lt;/h3&gt;

&lt;p&gt;I cannot reveal the actual questions because of NDA, but in my first interview, I had a question on Sliding Windows and Dynamic Programming.&lt;/p&gt;

&lt;p&gt;In my second interview which was held the next day, I had 3 questions. One was a Scheduling Problem based on the heap, the second was again a DP question. I was able to quickly answer these 2 questions, and there were around 10-12 mins left. So the interviewer gave me another DP question for which he just asked me to write the recursive function and how I would memoize it. I was able to do that as well.&lt;/p&gt;

&lt;p&gt;Both my interviews went well from my end, I didn't take any hints, wrote high code quality, and was able to successfully dry run all my solutions with edge cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Round 5: Hiring Committee
&lt;/h2&gt;

&lt;p&gt;After I finished my interviews, I had a long wait. According to what I've heard, there is a hiring committee that comprises four to five persons that have prior interview experience and are familiar with the hiring standards. They would review your resume, your code during interviews, and the feedback from the interviewers before making a final decision.&lt;/p&gt;

&lt;p&gt;For me, it was a long long wait. I very clearly remember the day. It was Maha Shasthi (the onset of Durga Puja), I woke up to a mail saying:&lt;/p&gt;

&lt;p&gt;"Congratulations on your SWE Summer Intern offer with Google India!"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AZAw9aPA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e7z09l5ooatv96i08inc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AZAw9aPA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e7z09l5ooatv96i08inc.png" alt="Congratulations on your SWE Summer Intern offer with Google India!" width="800" height="191"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It was a perfect blessing to me. I was ecstatic and overjoyed. It was an absolute dream come true moment for me and my family. Looking back I remember I felt very depressed when I was rejected by Microsoft twice. I gave my best in the Microsoft Engage Aptitude round yet wasn't even selected for the project building round. Then again when Microsoft came on-campus I was rejected after the OA round which still baffles me. But as they say "Whatever happens, happens for Good".&lt;/p&gt;

&lt;p&gt;So whenever something unexpected or bad happens to you, remember these lines:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JsGXiIsE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7i2yl5k7y2izb29898b6.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JsGXiIsE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7i2yl5k7y2izb29898b6.jpeg" alt="What was the 'Connecting the dots theory' of Steve Jobs? - Quora" width="602" height="313"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;I hope you liked my blog, do follow me for more such content. I wrote another blog sharing some tips on &lt;a href="https://www.arnabsen.dev/posts/tips-on-bagging-ppo/"&gt;how to convert your internship to PPO&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can learn more about me at &lt;a href="https://www.arnabsen.dev/about"&gt;arnabsen.dev/about&lt;/a&gt;. Have a nice day !!&lt;/p&gt;

</description>
      <category>interview</category>
      <category>career</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Important tips on bagging PPO during Internship and securing a Full-Time Role</title>
      <dc:creator>Arnab Sen</dc:creator>
      <pubDate>Sun, 29 Jan 2023 17:40:49 +0000</pubDate>
      <link>https://dev.to/arnabsen1729/important-tips-on-bagging-ppo-during-internship-and-securing-a-full-time-role-fdl</link>
      <guid>https://dev.to/arnabsen1729/important-tips-on-bagging-ppo-during-internship-and-securing-a-full-time-role-fdl</guid>
      <description>&lt;p&gt;If you are here after you have got an internship, then a big congratulations to you for getting an internship. I hope you are enjoying it and learning a lot. I am sure you are. But now you want to make sure that you get a PPO at the end of it. So, let's get started.&lt;/p&gt;

&lt;p&gt;I have been wanting to write this blog for a long time, I will try to include all the important points that I followed and have learned during my internship which helped me bag a PPO. I will break them down into 2 parts mainly, &lt;strong&gt;Technical&lt;/strong&gt; and &lt;strong&gt;Non-Technical&lt;/strong&gt;. Before that let me give you a little background.&lt;/p&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;I applied for Google Summer SWE Intern Opening on the &lt;a href="https://careers.google.com/" rel="noopener noreferrer"&gt;Google's careers portal&lt;/a&gt; with a referral. &lt;a href="https://arnabsen.dev/resume.pdf" rel="noopener noreferrer"&gt;My Resume&lt;/a&gt; got selected and I was called for 2 Rounds of Interviews. After that I got the offer and interned at Google for 10 weeks remotely with the Google Ads team. And finally, I was able to crack the PPO and got a full-time offer from Google as an SWE. I am planning to join them in July 2022.&lt;/p&gt;

&lt;p&gt;From&lt;br&gt;
&lt;iframe class="tweet-embed" id="tweet-1528345010164613123-821" src="https://platform.twitter.com/embed/Tweet.html?id=1528345010164613123"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1528345010164613123-821');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1528345010164613123&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;To&lt;br&gt;
&lt;iframe class="tweet-embed" id="tweet-1551660735440179201-631" src="https://platform.twitter.com/embed/Tweet.html?id=1551660735440179201"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1551660735440179201-631');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1551660735440179201&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;h2&gt;
  
  
  Conversion Process
&lt;/h2&gt;

&lt;p&gt;Before sharing the pieces of advice, I feel it's important to learn about the conversion steps. This will vary from company to company but overall the process remains the same.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Every Intern is assigned a &lt;strong&gt;project&lt;/strong&gt; and a mentor (at Google we call them &lt;strong&gt;host&lt;/strong&gt;) and a &lt;strong&gt;co-host&lt;/strong&gt;. The project is usually a part of the product that the team is working on. The mentor is a senior engineer who will be your guide throughout the internship. You will be working with your mentor and other engineers on the team.&lt;/li&gt;
&lt;li&gt;There will be two evaluations during the internship. The first evaluation called &lt;strong&gt;Mid Evaluation&lt;/strong&gt; happens after 5 weeks (since, my internship period was 10 weeks) and the &lt;strong&gt;Final Evaluation&lt;/strong&gt; happens at the last week of your internship. The Mid Evaluation is more of a check-in to see how you are doing and if you are on track. The Final Evaluation is more of a review of your work and the project. The host and co-host also gets to give their feedback on your performance and your project progress. This feedback plays a huge role in the final conversion.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Technical Advice
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Learn the basics
&lt;/h3&gt;

&lt;p&gt;You must have strong problem-solving abilities to work on the project that will be assigned to you. There are some basic Computer Science concepts that one should be familiar with. I will list them down below.&lt;/p&gt;

&lt;h4&gt;
  
  
  a. Version Control Systems
&lt;/h4&gt;

&lt;p&gt;No matter which company you are working at, you will be using a version control system. You must be familiar with the basics of version control systems. I would recommend you learn Git and GitHub. You can learn it from &lt;a href="https://www.youtube.com/watch?v=SWYqp7iY_Tc" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/RGOj5yH7evk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;At Google, we didn't use git, instead, we used Mercurial. But the fundamental concepts are the same. If you know how git works, learning a new version control system will just require you to learn the commands specific to that version control system.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi75lv558xq7e3kumodpt.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi75lv558xq7e3kumodpt.jpeg" alt="git logo" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  b. Basic Commandline
&lt;/h4&gt;

&lt;p&gt;There is a high chance that you will be working in a cloud environment and you must be comfortable with the terminal. You should be able to navigate through the file system, create directories, create files, delete files, etc. You should also be able to use basic commands like &lt;code&gt;cat&lt;/code&gt;, &lt;code&gt;grep&lt;/code&gt;, &lt;code&gt;sed&lt;/code&gt;, &lt;code&gt;awk&lt;/code&gt;, etc. You can learn about these commands from the man pages. For example, to learn about the &lt;code&gt;cat&lt;/code&gt; command, you can run &lt;code&gt;man cat&lt;/code&gt; in your terminal.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ZtqBQ68cfJc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h4&gt;
  
  
  c. Data Structures and Algorithms
&lt;/h4&gt;

&lt;p&gt;You should be familiar with the basic data structures and algorithms. You should be able to implement them in your language of choice and most importantly be aware of when to use which data structure and algorithm.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You don't need to be an expert in these topics. You just need to be familiar with them. But most of these companies have DSA questions in their interviews. So, it is important that you are familiar with them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I love the &lt;strong&gt;MIT 6.006 Introduction to Algorithms&lt;/strong&gt; lectures, they have helped me build the foundation of algorithms. You can find the playlist &lt;a href="https://youtu.be/HtSuA80QTyo?list=PLUl4u3cNGP61Oq3tWYp6V_F-5jb5L2iHb" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/HtSuA80QTyo"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Knowing the syntax of the language you will be using
&lt;/h3&gt;

&lt;p&gt;Sometimes you can ask the recruiter about the tech stack that you will be using. But most of the time, you won't be able to know the tech stack beforehand. But, you can still learn the basics of the language that is popularly used in the company. For example, I knew that Google uses C++, Java, and Golang a lot in their backend. I already knew C++ and Golang. So I learned the basics of Java before joining Google. This helped me save a lot of time during the internship picking up the language.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Learn Design Patterns
&lt;/h3&gt;

&lt;p&gt;Design patterns are important for developers to understand because they provide proven solutions to common software design problems. By using design patterns, developers can improve the quality, reusability, and maintainability of their code.&lt;/p&gt;

&lt;p&gt;While you don't need to know every design pattern in existence, it's helpful to have a good understanding of the most common design patterns and when to use them. This knowledge can save a lot of time and effort by allowing you to reuse tried-and-true solutions to common problems, rather than having to reinvent the wheel every time you encounter a new challenge.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftceweqscxu6qkyqn68yr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftceweqscxu6qkyqn68yr.png" alt="23 Design Patterns" width="800" height="776"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  4. Write clean code
&lt;/h4&gt;

&lt;p&gt;I can't stress this enough. Writing clean code is very important especially if you are interning at a big organisation like Google. Every change you make goes through a rigorous review process. If your code is not clean, it will be rejected. So, you must write clean code. Here are some points that you should keep in mind while writing clean code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Keep it simple:&lt;/strong&gt; When writing code, it's important to avoid unnecessary complexity. Simple, easy-to-understand code is usually easier to maintain and debug.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use clear and descriptive names:&lt;/strong&gt; Choosing clear and descriptive names for variables, functions, and other elements of the code can make it much easier to read and understand. Avoid using abbreviations or single-letter names, unless they are well-known and widely understood.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use comments:&lt;/strong&gt; Comments can be a helpful tool for explaining the purpose and functionality of different parts of the code. However, it's important to use comments sparingly and only when they are truly necessary, as too many comments can make the code harder to read.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Follow a consistent style:&lt;/strong&gt; Consistency is key when it comes to writing clean code. Using a consistent style for indentation, spacing, and other elements of the code can make it easier to read and understand. It's also a good idea to follow established coding standards and guidelines, such as those provided by the programming language's community or the company you work for.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fabl1kljmxgsk53hpliv2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fabl1kljmxgsk53hpliv2.png" alt="Code Quality Meme" width="550" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Learn testing
&lt;/h3&gt;

&lt;p&gt;Testing is an important part of software development. It's important to test your code to make sure it works as expected and to catch any bugs that might have been introduced during development. Testing can also help you to ensure that your code is clean and easy to understand. There are different types of testing like unit testing, integration testing, etc. Knowing about these testing types will help you a lot.&lt;/p&gt;

&lt;p&gt;Here is a free course on &lt;a href="https://thoughtbot.com/upcase/fundamentals-of-tdd" rel="noopener noreferrer"&gt;Test Driven Development&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Know how to write a Design Doc
&lt;/h3&gt;

&lt;p&gt;At Google, we heavily focus on the Design Doc. Even before we write a piece of code for a particular implementation we have to make sure we have analysed every possible edge case, and technical and non-technical requirements. Design documents also help with communication among team members and can serve as a reference for future maintenance and updates to the software.&lt;/p&gt;

&lt;p&gt;There are certain key points that need to be covered in a Design Doc like Architecture, Requirements, Design, User Interface, Testing .etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.industrialempathy.com/posts/design-docs-at-google/" rel="noopener noreferrer"&gt;Here&lt;/a&gt; is a great post that talks in depth about Design Docs.&lt;/p&gt;

&lt;p&gt;This is a &lt;a href="https://docs.google.com/document/d/1pgMutdDasJb6eN6yK6M95JM8gQ16IKacxxhPXgeL9WY/edit" rel="noopener noreferrer"&gt;sample template of a Design Document&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Non-Technical Advice
&lt;/h2&gt;

&lt;p&gt;In addition to the technical advice, I would also like to share some non-technical advice that I followed during my internship.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Be proactive
&lt;/h3&gt;

&lt;p&gt;This was something my host pointed out in my mid-evaluation. I was being too dependent initially on my mentor, waiting for her to tell me the next steps. But later I took the advice. So I started planning my work, assigning tasks to myself, and taking the initiative to solve the problems. But obviously, I kept my mentor in the loop. This takes me to the next point.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Keep your mentor (host and co-host) in the loop
&lt;/h3&gt;

&lt;p&gt;Remember, your host and co-host will be evaluating you at the end of your internship. Also, they have their deadline and they will be busy with their work. So, you must keep them in the loop. You should be able to communicate with them and tell them what you are working on and what problems you are facing. This will help them to guide you better.&lt;/p&gt;

&lt;p&gt;We had a weekly meeting with our host and co-host but even then I would update them on my progress every alternate day so that they are aware of what I am working on. I would also disclose the problems I faced and the solutions I found.&lt;/p&gt;

&lt;p&gt;There is a really good article on &lt;a href="https://jvns.ca/blog/brag-documents/?utm_source=pocket_mylist" rel="noopener noreferrer"&gt;Writing a brag document&lt;/a&gt; that I would recommend you to read.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Be open to feedback
&lt;/h3&gt;

&lt;p&gt;No matter how big a company you are interning at, you should remember that you are still very new to this field and there is a lot to improve. Feedback from your host/co-host or other team members can help you identify areas of their work that needs improvement. It might be difficult to accept the feedback at first but you should be open to it. You should be able to take the feedback positively and work on improving yourself.&lt;/p&gt;

&lt;p&gt;Not always your mentor will reach out to you to give you feedback. If required you might have to reach out to them and ask for feedback. You can ask them to give you feedback on your code, your communication skills, your problem-solving skills, etc. This also shows that you are proactive and you are willing to make improvements.&lt;/p&gt;

&lt;p&gt;A good place to get feedbacks from your host/co-host is through 1:1 meetings. Here is a good video on &lt;a href="https://youtu.be/ADWkkJtZna4" rel="noopener noreferrer"&gt;The Art Of The 1:1 Meeting&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/ADWkkJtZna4"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Time management
&lt;/h3&gt;

&lt;p&gt;Plan out the tasks that you will have to do, assign priority to them and then start working on them. This will help you to manage your time better. You should also be able to estimate the time that you will need to complete a task. Initially, you may end up overestimating or underestimating the time but as you gain more experience, you will be able to estimate the time better.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Ask questions
&lt;/h3&gt;

&lt;p&gt;An internship usually lasts 10-12 weeks, which is not a lot of time. So if you are stuck at something, you can't afford to lose time. You should be able to ask questions to your mentor and other team members. But before that make sure you have done a fair amount of research on your end as well.&lt;/p&gt;

&lt;p&gt;You have to ask the right questions to get quick answers. If you came across an error message, explain properly how to reproduce the error, and what the error message is. Share the code snippet that might be causing the error, or share the files you are working on. Further, the approaches you have already taken to solve the problem. This will help the person you are asking the question to understand the problem better. Also, make sure you are asking the question in the right channel. For example, if you are stuck on a coding problem, you should ask your mentor or other team members. But if you are stuck in a process, you should ask your host/co-host.&lt;/p&gt;

&lt;p&gt;Here is a great article on &lt;a href="https://jvns.ca/blog/good-questions/?utm_source=pocket_mylist" rel="noopener noreferrer"&gt;How to ask questions the smart way&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Podcast w/ Aniket
&lt;/h2&gt;

&lt;p&gt;I was recently on a podcast where we went through some of these points in more depth. Watch the video here:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/0EB-np28BZU"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;These are some of the things that I followed during my internship. I hope this article will help you to prepare for your internship. One thing you should also keep in mind is to enjoy the internship. It is a great opportunity to learn and grow, network with people and build your resume. Don't burnout yourself before or during the internship. Take breaks, go out with your friends, play games, watch movies, etc. This will help you to stay motivated and perform better.&lt;/p&gt;

&lt;p&gt;If you have any questions, feel free to ask in the comments. I will try my best to answer them. Also, if you have any other advice that you would like to share, feel free to do so in the comments.&lt;/p&gt;

</description>
      <category>crypto</category>
      <category>trading</category>
      <category>csharp</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>My experience of Summer Of Bitcoin'21</title>
      <dc:creator>Arnab Sen</dc:creator>
      <pubDate>Tue, 17 Jan 2023 12:06:14 +0000</pubDate>
      <link>https://dev.to/arnabsen1729/my-experience-of-summer-of-bitcoin21-2l5f</link>
      <guid>https://dev.to/arnabsen1729/my-experience-of-summer-of-bitcoin21-2l5f</guid>
      <description>&lt;p&gt;On June 26, I received an email saying that I was one of the 50 students selected for the &lt;strong&gt;Summer of Bitcoin 2021&lt;/strong&gt; program. I was really happy and felt proud of myself because to be very honest I didn't have high hopes at that point. In this blog, I will cover the selection process, and my experience at Summer of Bitcoin and will also share some tips for those who are interested in this program.&lt;/p&gt;

&lt;h2&gt;
  
  
  About the Summer of Bitcoin
&lt;/h2&gt;

&lt;p&gt;A global program that matches students with open source, free software, and technology-related organizations working on bitcoin to write code and become part of these communities while making some BTC along the way! The organizations provide mentors who act as guides through the entire process, from learning about the community to contributing code. Students get involved in and become familiar with the bitcoin open-source community and put their summer break to good use.&lt;/p&gt;

&lt;p&gt;To know more visit the Summer Of Bitcoin &lt;a href="https://www.summerofbitcoin.org/"&gt;website&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XHVN1PmA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xyu6dyehm2meb24ybz66.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XHVN1PmA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xyu6dyehm2meb24ybz66.png" alt="Summer Of Bitcoin Logo" width="500" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🪴 Selection Process
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How I came to know about the program
&lt;/h3&gt;

&lt;p&gt;I was scrolling through LinkedIn when I came across a post about the Summer Of Bitcoin. There was a form attached to it. It had some basic questions and a couple of essay questions like why do you want to take part etc. My tips for filling out the form would be to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Be truthful and original.&lt;/strong&gt; You have to understand that those who will select you are way more experienced than you so don't just copy-paste from random sites.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Make sure you don't make any grammatical errors.&lt;/strong&gt; What I usually do is first write it down in Google Docs and use spell-check. You can also install the &lt;a href="https://www.grammarly.com/"&gt;Grammarly&lt;/a&gt; extension to avoid typos and grammatical errors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Gather information&lt;/strong&gt;. Go through the official websites, or take help from past participants. In my case, this was the first time, so there wasn't much public information available, but yeah I did visit the official website. The reason I am saying this is you can understand what the motive of the program is and then write your essays on the same line.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1️⃣&lt;/strong&gt; Round 1: Problem-Solving
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;We are not supposed to discuss the problem and our approaches, so I would refrain from giving details&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It was not a typical CP question, rather was more real-life and bitcoin-related. We had to find an optimal solution but satisfy the conditions specified. And then submit our code. After spending around 2 days on the problem I was somewhat satisfied with my result, and I thought of submitting it. I also described my approach in a README file.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2️⃣&lt;/strong&gt; Round 2: Follow-up question
&lt;/h3&gt;

&lt;p&gt;Then the next day I received a follow-up question in the email where I had to explain in detail a better approach to my previous solution. I had one more approach in my mind which I then explained and also proved how theoretically it is supposed to give a better solution.&lt;/p&gt;

&lt;p&gt;And a few days later I received this mail:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--F9-9406a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ggwil7f6yisx6tf78svl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F9-9406a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ggwil7f6yisx6tf78svl.png" alt="Welcome to the next round mail" width="800" height="116"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yayy !! My solution was in the &lt;strong&gt;top 1%&lt;/strong&gt; among thousands of applicants. At this point, I was pretty confident.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;3️⃣&lt;/strong&gt; Round 3: "Navigating Ambiguity"
&lt;/h3&gt;

&lt;p&gt;We were asked to find an issue in the official &lt;a href="https://github.com/bitcoin/bitcoin"&gt;Bitcoin&lt;/a&gt; repo and explain what approach we would take to solve it. So I went to the issues tab and I didn't understand a single word since I was an absolute beginner. But I spent around 2 days trying to figure out the issues, even while doing this I learned a lot about stuff like fuzzing, AFL, and many other concepts. I picked one particular issue, tried to understand it end to end, researched a little bit, and came across an approach that I then explained.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;4️⃣&lt;/strong&gt; Round 4: Telephonic Interview
&lt;/h3&gt;

&lt;p&gt;2 days later I received a calendly link for a telephone round. In the telephonic round, I was asked to give a brief introduction of myself, my past experiences, and achievements, technical skills, and projects. Also, I was asked some questions like &lt;em&gt;why I wanted to be a part of this program&lt;/em&gt; and &lt;em&gt;what my expectations are&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;After the call, my interviewer sent me a link for a video interview which was scheduled an hour later.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;5️⃣&lt;/strong&gt; Round 5: Final Interview
&lt;/h3&gt;

&lt;p&gt;Here I was asked more about my knowledge of Bitcoin and Blockchain, which programming aspects I like to work on, and some more HR questions. I also asked him questions regarding the program.&lt;/p&gt;

&lt;p&gt;I prepared myself by researching a little bit on Bitcoin, going through the Bitcoin whitepaper, and watching a couple of introductory videos.&lt;/p&gt;

&lt;p&gt;At the end of the conversation, I was pretty confident that I was able to ace it, cause I was getting positive vibes and my interviewer also shared some resources to get started (I have added them below).&lt;/p&gt;

&lt;h2&gt;
  
  
  📼 Sessions
&lt;/h2&gt;

&lt;p&gt;We had some really amazing sessions with folks who are associated with Bitcoin for years. They have made contributions to Bitcoin Core and other bitcoin-related projects, and every one of them shared their perspective towards Bitcoin and how revolutionary this concept of a "Decentralised monetary system" is.&lt;/p&gt;

&lt;p&gt;Here are some of the links to the recorded sessions:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=lnEWDLScep0&amp;amp;t=17s"&gt;The CS in Bitcoin with Sanket Kanjalkar&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/lnEWDLScep0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=URMoDCCvjdI"&gt;Deep Dive Into Bitcoin Mechanics with Matthew Zipkin&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/URMoDCCvjdI"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=l-1Cur4I5yY"&gt;Decentralized open-source development with Amiti Uttarwar&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/l-1Cur4I5yY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=yZxwre6aT44"&gt;Layering to Scale Bitcoin with Will Clark&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/yZxwre6aT44"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You will find more on the &lt;a href="https://www.youtube.com/channel/UCu8iAf7tWfJNy2dcY7KvRBg/videos"&gt;Summer Of Bitcoin Youtube Channel&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Then we had some lectures which were given by &lt;a href="https://twitter.com/kallerosenbaum"&gt;Kalle Rosenbaum&lt;/a&gt;, he is the author of the book &lt;strong&gt;Grokking Bitcoin&lt;/strong&gt;. I would suggest this book to any beginner. The book explains how a system of Cookie Token used in a Cafe can be improved step by step and we will end up with a system like Bitcoin. The last day of the first week ended with experimenting with the &lt;code&gt;bitcoin-cli&lt;/code&gt;. We created our own bitcoin full node in our machine and created a wallet. For testing purposes, we used the &lt;em&gt;signet&lt;/em&gt;. Kalle gave us some coins which we then used to make transactions among our peers.&lt;/p&gt;

&lt;p&gt;In between the lectures we used to have Breakout rooms that would give us a chance to discuss with peers and solve questions and resolve each other's doubts.&lt;/p&gt;

&lt;p&gt;By the end of the first week, I went from having very little knowledge about Bitcoin to having a good grasp on fundamentals like consensus (proof-of-work), the P2P network, how bitcoin protocol upgrades take place, and innovations taking place in Bitcoin like the SegWit, Taproot, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;📦&lt;/strong&gt; Project Matching
&lt;/h2&gt;

&lt;p&gt;Everyone was matched with a mentor and was assigned a Project. I was assigned the amazing &lt;a href="https://b10c.me/"&gt;0xB10C&lt;/a&gt; and my project was to improve the "User-Space, Statically Defined Tracing" (USDT) support for Bitcoin Core. For the next few weeks, we collaborated with our mentors and made contributions to the various projects at the same time reviewing each other's work. I worked on adding some &lt;code&gt;utxocache&lt;/code&gt; tracepoints for events like &lt;code&gt;flush&lt;/code&gt;, &lt;code&gt;addCoin&lt;/code&gt;, &lt;code&gt;spendCoin&lt;/code&gt; etc. I learned a lot about the eBPF (extended Berkeley Packet Filter) technology, tracepoints, Linux Observability, navigating through large codebases like Bitcoin, and about open source in general.&lt;/p&gt;

&lt;h2&gt;
  
  
  🗓️ Weekly Seminars
&lt;/h2&gt;

&lt;p&gt;For the first 5 weeks, we also had weekly seminars on Bitcoin and Lightning Protocol Development. I was in the Bitcoin Protocol Development, so we had these topics:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Week 1:&lt;/strong&gt; Welcome to Bitcoin Protocol Development&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Week 2:&lt;/strong&gt; Segwit&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Week 3:&lt;/strong&gt; Mining &amp;amp; Network Block Propagation&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Week 4:&lt;/strong&gt; P2P&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Week 5:&lt;/strong&gt; Script &amp;amp; Wallets&lt;/p&gt;

&lt;p&gt;Every week, we would be matched with a random peer and assigned a particular question on the topic we had that week. We have to work with our partners to brainstorm answers to that question. Then every week we will meet in a breakout room and discuss our findings with everyone else. It was so much fun learning and sharing our research with our peers.&lt;/p&gt;
&lt;h2&gt;
  
  
  📚 Resources
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://learn.saylor.org/course/view.php?id=468"&gt;PRDV151: Bitcoin for Everybody&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://learn.saylor.org/course/view.php?id=500"&gt;CS120: Bitcoin for Developers I&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://rosenbaum.se/book/grokking-bitcoin.html"&gt;Grokking Bitcoin&lt;/a&gt; by &lt;a href="https://twitter.com/kallerosenbaum"&gt;Kalle Rosenbaum&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.coursera.org/learn/cryptocurrency"&gt;Bitcoin and Cryptocurrency Technologies&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/bitcoinbook/bitcoinbook"&gt;Mastering Bitcoin&lt;/a&gt; for more technical insights.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/@amitiu/onboarding-to-bitcoin-core-7c1a83b20365"&gt;Onboarding to Bitcoin Core by Amiti Uttarwar&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://bitcoin.org/bitcoin.pdf"&gt;Bitcoin Whitepaper&lt;/a&gt; (must read !!)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/BlockchainCommons/Learning-Bitcoin-from-the-Command-Line"&gt;Learning-Bitcoin-from-the-Command-Line&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After you have a good understanding of the fundamentals you can also dive into &lt;a href="https://chaincode.gitbook.io/seminars/"&gt;https://chaincode.gitbook.io/seminars/&lt;/a&gt; to get into the depth of each concept.&lt;/p&gt;
&lt;h2&gt;
  
  
  📝 Takeaways
&lt;/h2&gt;

&lt;p&gt;Prior to this Summer Of Bitcoin, I had very little experience with cryptocurrency, blockchain, and also open-source. It was not just a bitcoin learning experience but we had career-building, resume, and interview prep sessions too. I also kept a talk on Bitcoin Script. To make things even more amazing we also got some swags !! T-shirt and a Hardware Crypto Wallet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ud7pogmr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/almjb13ozra2yblwj984.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ud7pogmr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/almjb13ozra2yblwj984.png" alt="Ledger Nano S and Summer of Bitcoin Tee" width="800" height="536"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But the most important takeaway would be the new connections I made, I made a lot of new friends who are really amazing at what they do, and I am still working with my mentor &lt;code&gt;0xB10C&lt;/code&gt; and I will be joining back this summer as a student coach for the next cohort.&lt;/p&gt;
&lt;h2&gt;
  
  
  Final Notes
&lt;/h2&gt;

&lt;p&gt;Since I was a part of the first cohort of Summer Of Bitcoin, the procedure was a bit different. This time they have made some updates to their application procedure and have also introduced Designer Track. You will find the new timeline on their &lt;a href="https://www.summerofbitcoin.org/apply"&gt;website&lt;/a&gt;. To keep getting updates follow &lt;a href="https://twitter.com/summerofbitcoin"&gt;@summerofbitcoin&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I would love to extend my gratitude to &lt;a href="https://twitter.com/adibitcoin"&gt;Adi Shankara&lt;/a&gt;, &lt;a href="https://twitter.com/Caralie_C"&gt;Caralie Chrisco&lt;/a&gt;, and &lt;a href="https://twitter.com/adamcjonas"&gt;Adam Jonas&lt;/a&gt; for giving us this amazing opportunity and to my mentor 0xB10C for always helping me with my doubts. 0xB10C is very active in the Bitcoin Development Community you should definitely check out his work at &lt;a href="https://b10c.me/"&gt;b10c.me&lt;/a&gt; and follow him &lt;a href="https://twitter.com/0xB10C"&gt;@0xB10C&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For those who are looking forward to applying for the next cohort of Summer of Bitcoin, all the very best. If you have any doubts or questions feel free to contact me, my DMs are always open.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://twitter.com/ArnabSen1729"&gt;@ArnabSen1729&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.linkedin.com/in/arnabsen1729/"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/arnabsen1729"&gt;GitHub&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="//arnabsen1729@gmail.com"&gt;Gmail&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I61YwWG7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q3nm309320gxtbz6cjws.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I61YwWG7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q3nm309320gxtbz6cjws.png" alt="My Testimonial on Summer Of Bitcoin Website" width="636" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(Source: &lt;a href="https://www.summerofbitcoin.org/"&gt;https://www.summerofbitcoin.org/&lt;/a&gt;)&lt;/em&gt;&lt;/p&gt;



&lt;p&gt;I was recently invited to a podcast where I shared my Summer of Bitcoin experience and advice for the application rounds. We also discussed the future of Bitcoin and job opportunities in this space. You can check out the podcast as well 👇&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/_nnpHfuiPzs"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
      <category>opensource</category>
      <category>programming</category>
    </item>
    <item>
      <title>Hello World! in Rescript-React</title>
      <dc:creator>Arnab Sen</dc:creator>
      <pubDate>Fri, 05 Mar 2021 04:50:46 +0000</pubDate>
      <link>https://dev.to/arnabsen1729/hello-world-in-rescript-react-3525</link>
      <guid>https://dev.to/arnabsen1729/hello-world-in-rescript-react-3525</guid>
      <description>&lt;h1&gt;
  
  
  Hello World! in Rescript React
&lt;/h1&gt;

&lt;p&gt;Talking a bit about Rescript, it is a new language that combines the best parts of JS and OCaml. It has a compiler that compiles to JS and leverages OCaml’s static and sound type system. Many people prefer this approach to TypeScript. The compiler was originally named BuckleScript but in 2020, it was rebranded to ReScript because of its Reason-like syntax.&lt;/p&gt;

&lt;p&gt;Rescript docs are well written, organized, and maintained actively. &lt;a href="https://rescript-lang.org/docs/manual/latest/introduction" rel="noopener noreferrer"&gt;Link to their documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you have a basic knowledge of Rescript syntax and React, then we are good to go. &lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up the project
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Start with the command &lt;code&gt;npm init -y&lt;/code&gt;. If you simply do &lt;code&gt;npm init&lt;/code&gt; it will ask you to fill in a couple of data, if you want them to be default values add the &lt;code&gt;-y&lt;/code&gt; tag.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm init &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now, let's install the ReScript compiler locally. The reason we are installing it with &lt;code&gt;--save-dev&lt;/code&gt; is because we need it as a dev dependency.The Rescript compiler will compile the &lt;code&gt;*.res&lt;/code&gt; files to JS files. This is actually called source to source compilation.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; bs-platform
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Before, moving on to the configuration part, let's install the &lt;code&gt;rescript-react&lt;/code&gt; plugin.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; @rescript/react &lt;span class="nt"&gt;--save&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now, we have to set up a &lt;code&gt;bsconfig.json&lt;/code&gt; file. Create this file and then copy and paste the following into it:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;bsconfig.json&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"$schema"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://raw.githubusercontent.com/rescript-lang/rescript-compiler/master/docs/docson/build-schema.json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"project-name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"sources"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"dir"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"src"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"subdirs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"package-specs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"module"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"es6"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"in-source"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"suffix"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;".bs.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"namespace"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"bs-dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"@rescript/react"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"ppx-flags"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"reason"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"react-jsx"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"warnings"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"+101"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"refmt"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's understand the config for a moment, going line by line:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;$schema&lt;/strong&gt;: Editors like VSCode have a feature of schema autocompletion, and to get that we need to specify the schema. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;name&lt;/strong&gt;: It is the name of the library or the main project name in simple words.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;the bsconfig.json name should be the same as the package.json name, to avoid confusing corner-cases. However, this means that you can't use a camelCased names such as MyProject, since package.json and npm forbid you to do so (some file systems are case-insensitive).&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;sources&lt;/strong&gt;: We have to specify where the source files will reside. Usually, it is the &lt;code&gt;/src&lt;/code&gt; directory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;suffix&lt;/strong&gt;: The file extensions after compilation by the Rescript compiler, can be &lt;code&gt;.js&lt;/code&gt; or &lt;code&gt;.bs.js&lt;/code&gt;. ( Although, the latter is always preferred )&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;bs-dependencies&lt;/strong&gt;: The list of Rescript dependencies, and since we are using the &lt;code&gt;rescript-react&lt;/code&gt; we have to specify that here. There is also &lt;code&gt;bs-dev-dependencies&lt;/code&gt;. These are very similar to how we mention node dependencies in &lt;code&gt;package.json&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;reason&lt;/strong&gt;: Since we will be using React-JSX, we have to specify &lt;code&gt;{"react-jsx": 3}&lt;/code&gt;. &lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;For normal Rescript projects, the &lt;code&gt;bs-dependencies&lt;/code&gt; will have &lt;code&gt;[]&lt;/code&gt; and &lt;code&gt;reason&lt;/code&gt; will be &lt;code&gt;{}&lt;/code&gt;. To learn more about the config refer &lt;a href="https://rescript-lang.org/docs/manual/latest/build-configuration-schema" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;To compile the source files we have to add two scripts in our &lt;code&gt;package.json&lt;/code&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;package.json&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"clean"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"bsb -clean-world"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"bsb -make-world -w"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;start&lt;/strong&gt;: will compile the res files and will run in watch mode i.e will continuously look for changes and compile it. It is always advised to run the start script and then code the Res files, cause the intelligent rescript compilation helps a lot and makes the coding easier for beginners to the language. &lt;br&gt;
&lt;strong&gt;clear&lt;/strong&gt;: will clean/remove the previously compiled &lt;code&gt;*.bs.js&lt;/code&gt;files. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now, install &lt;code&gt;react&lt;/code&gt; and &lt;code&gt;react-dom&lt;/code&gt; packages.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;react react-dom &lt;span class="nt"&gt;--save&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Finally, we will use &lt;code&gt;snowpack&lt;/code&gt; to build and bundle the project during development. In &lt;code&gt;snowpack&lt;/code&gt; each file needs to be built only once and then is cached forever. When a file changes, Snowpack rebuilds that single file. There’s no time wasted re-bundling every change, just instant updates in the browser (made even faster via Hot-Module Replacement (HMR)). It is really fast. 
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.snowpack.dev%2Fimg%2Fsnowpack-unbundled-example-3.png" alt="img"&gt;
Again we will install snowpack as a dev dependency:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; snowpack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Make a &lt;code&gt;snowpack.config.js&lt;/code&gt; file and copy-paste this. Since we are not using any kind of plugins there is nothing to specify over here.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;snowpack.config.j&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Example: snowpack.config.js&lt;/span&gt;
&lt;span class="c1"&gt;// The added "@type" comment will enable TypeScript type information via VSCode, etc.&lt;/span&gt;

&lt;span class="cm"&gt;/** @type {import("snowpack").SnowpackUserConfig } */&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="cm"&gt;/* ... */&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now, we have to add a couple of npm scripts for snowpack to start the server and build the project.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;package.json&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"snowpack dev"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"snowpack build"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At, this point we are done setting up dependencies, and your final &lt;code&gt;package.json&lt;/code&gt; should look like this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;package.json&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"react-res-test"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"main"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"index.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"clean"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"bsb -clean-world"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"bsb -make-world -w"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"snowpack dev"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"snowpack build"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"keywords"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"author"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"license"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ISC"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"devDependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"bs-platform"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^9.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"snowpack"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^3.0.13"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"@rescript/react"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^0.10.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"react"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^17.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"react-dom"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^17.0.1"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Start writing your Hello World Code!!
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;First start off with a simple &lt;code&gt;index.html&lt;/code&gt; in your root directory. Paste this basic template. One important thing is that there should be a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; with &lt;code&gt;id="root"&lt;/code&gt; inside which the React components will be rendered. This is how React works, if you already have some experience then you would know. Also, we have to include the compiled &lt;code&gt;index.bs.js&lt;/code&gt; file. You can simply copy-paste this HTML. If you will use &lt;code&gt;index.css&lt;/code&gt; then create a file and add its relative path.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;index.html&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;ReScript React&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"index.css"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"root"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"module"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"src/index.bs.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now create a folder &lt;code&gt;src&lt;/code&gt; and create a new file &lt;code&gt;src/index.res&lt;/code&gt;. Inside the &lt;code&gt;index.res&lt;/code&gt; file just copy-paste this for the time being. We will dive into the code later on. Currently, let's test if all the setup we did was a success.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rescript"&gt;&lt;code&gt;&lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="nn"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"#root"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nc"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nn"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nn"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello World!"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;, &lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nc"&gt;None&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nn"&gt;Js&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Error: could not find react element"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: &lt;em&gt;Here we are querying for &lt;code&gt;#root&lt;/code&gt; in the DOM(index.html) i.e looking for an element with &lt;code&gt;id="root"&lt;/code&gt;. If in the &lt;code&gt;index.html&lt;/code&gt; you have created some other id let's say &lt;code&gt;xyz&lt;/code&gt; then over here you have to replace &lt;code&gt;#root&lt;/code&gt; with &lt;code&gt;#xyz&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Now, in the terminal run the command to compile the &lt;code&gt;index.res&lt;/code&gt; file.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm run start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you run this, a new file &lt;code&gt;index.bs.js&lt;/code&gt; will be created. ( This is why we included the &lt;code&gt;index.bs.js&lt;/code&gt; file in &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag in &lt;code&gt;index.html&lt;/code&gt; ).&lt;/p&gt;

&lt;p&gt;To build the react app run this is another terminal window.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will start a snowpack server at &lt;code&gt;localhost:8080&lt;/code&gt; with hot reload. Visit the URL in your browser and if you see &lt;code&gt;Hello World!&lt;/code&gt; Congratulations!! You are now ready to create your rescript-react project.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; Don't keep your &lt;code&gt;index.css&lt;/code&gt; file empty if you have linked it to the &lt;code&gt;index.html&lt;/code&gt;. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Final folder structure will be like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;├── bsconfig.json
├── index.css
├── index.html
├── package.json
├── package-lock.json
├── snowpack.config.js
└── src
    ├── index.bs.js
    └── index.res
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Was it a long process? Yeah, kind of. But every time you won't have to go through all. Here I have already created a repo with all these steps. Simply clone it and get started:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/arnabsen1729/rescript-react-starter" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub-link-card.s3.ap-northeast-1.amazonaws.com%2Farnabsen1729%2Frescript-react-starter.png"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>tutorial</category>
      <category>functional</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
