<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shashank Aggarwal on Medium]]></title>
        <description><![CDATA[Stories by Shashank Aggarwal on Medium]]></description>
        <link>https://medium.com/@agg-shashank?source=rss-396282b88d6f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Shashank Aggarwal on Medium</title>
            <link>https://medium.com/@agg-shashank?source=rss-396282b88d6f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 16:09:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@agg-shashank/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Setting up a Dask cluster using Ansible]]></title>
            <link>https://agg-shashank.medium.com/setting-up-a-dask-cluster-using-ansible-7476d297f438?source=rss-396282b88d6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7476d297f438</guid>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[dask]]></category>
            <dc:creator><![CDATA[Shashank Aggarwal]]></dc:creator>
            <pubDate>Wed, 20 Jan 2021 23:13:59 GMT</pubDate>
            <atom:updated>2021-02-07T16:42:41.500Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*mjB4TnMhuGbSF3j1udWUHw.png" /></figure><p>To create a dask cluster spanning multiple machines connected via SSH communication, Dask provides the following builtin methods :</p><ul><li>Manual setup using the dask-scheduler and dask-worker commands</li><li>Using the dask-ssh command, which accepts a list of hostnames and other SSH authentication options, and spawns the schdeuler and hostnames on the hosts</li></ul><p>(Detailed docs for these and other methods at <a href="https://docs.dask.org/en/latest/setup.html">https://docs.dask.org/en/latest/setup.html</a>)</p><p>The first method above is simple, but tedious when working with a large cluster since it requires us to SSH into each of the hosts separately, and run the commands there.</p><p>The dask-ssh command is quite handy. However, it can be too simple at times. For example, if the hosts on our cluster use username/password for authentication or separate SSH keys per host, then this command falls short.</p><p>Another approach is to use one of the several popular infrastructure-automation tools (Puppet, Ansible etc.) to easily set up and tear down the dask cluster. Here, we will talk about Ansible since it is fairly popular and requires *almost* zero setup.</p><p>From here on, we assume that all the nodes have the prerequisites installed (Python, dask and dask-distributed). While this step can also be automated with Ansible, this is a one-time setup. So not much time to save here :/</p><p>Also, the scheduler is assumed to be already running on a known host (say at 11.22.33.44:8786). The steps to setup a dask-cluster would then be:</p><ol><li>Install ansible on your local machine. Ansible communicates with all the hosts using simple SSH, and requires no setup on the hosts themselves.</li><li>Create an ansible inventory file (hosts.ini). This file contains details about all the hosts (their IP addresses, path to dask binaries on the host etc.) on which we would like to spawn workers, and other variables such as:</li></ol><ul><li>The scheduler’s address</li><li>SSH authentication details (keys, username/password)</li></ul><p>A sample inventory file for 6 hosts (divided into 2 groups) looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61cf87b3a21a41b25dc7db5a429106c7/href">https://medium.com/media/61cf87b3a21a41b25dc7db5a429106c7/href</a></iframe><p>In the first section, we have defined properties common to all nodes (such as the scheduler address, SSH key etc.). If we use separate SSH keys for different node, this can be done by specifying the ansible_ssh_private_key_file separately per node or per node-group.</p><p>Note the grouping being done here. This is done to logically separate our hosts if needed. This is useful when we want to handle differences in our nodes (For example, the location of dask binaries on the host, node-specific environment variables which we would like to pass to the dask-worker command etc.). Of course, this kind of grouping is optional, and all the nodes can be defined in a single group, or even separately, each with their own parameters.</p><p>3. Create a playbook to spawn the dask worker. This .yaml file contains the instructions which ansible will run on the hosts specified in the inventory. A simple playbook to run dask-workers looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cec1ef17a0b8c701c932be272dfd09e6/href">https://medium.com/media/cec1ef17a0b8c701c932be272dfd09e6/href</a></iframe><p>Note the shell command. It runs the dask-worker command, adding all the variables we defined in the inventory as command line arguments, which can be used in our Python worker code.</p><p>4. (<em>optional</em>) Create another playbook to stop all the dask workers. This is useful when debugging the setup process, and avoids having to SSH into each host to kill the dask-worker. This playbook essentially greps ps for dask-workers and sends a SIGTERM signal to it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77dd06b47dea59fe1c2b3a9318f1dc24/href">https://medium.com/media/77dd06b47dea59fe1c2b3a9318f1dc24/href</a></iframe><p>5. Test if ansible is able to communicate with all the nodes (6 here) using:</p><pre>ansible -i hosts all -m ping</pre><p>Next, start the cluster using:</p><pre>ansible-playbook -i hosts cluster-start.yml</pre><p>If needed, test if the cluster works by running something like this on your local machine:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/839e2b9060433fcb2da48771390d52ed/href">https://medium.com/media/839e2b9060433fcb2da48771390d52ed/href</a></iframe><p>6. (<em>optional</em>) Stop all the dask-workers using:</p><pre>ansible-playbook -i hosts cluster-stop.yml</pre><h4>Appendix</h4><ol><li>If using a username/password combination instead of keys, replace the ansible_ssh_private_key_file with the ansible_ssh_pass paramenter in the inventory. It is advisable to use keys though. To generate a key, use the ssh-keygen command, and then copy the key to all the hosts using ssh-copy-id -i &lt;key_name_from_above&gt; &lt;host-address&gt; .</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7476d297f438" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An introduction to using Wikidata APIs]]></title>
            <link>https://agg-shashank.medium.com/an-introduction-to-using-wikidata-apis-a678ee6d2968?source=rss-396282b88d6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a678ee6d2968</guid>
            <dc:creator><![CDATA[Shashank Aggarwal]]></dc:creator>
            <pubDate>Fri, 19 Jun 2020 17:29:35 GMT</pubDate>
            <atom:updated>2020-06-19T17:35:08.985Z</atom:updated>
            <content:encoded><![CDATA[<p>An introduction to using Wikidata APIs</p><p>Wikidata is a very generic knowledge base, and contains information about (almost) everything under the sun. Think of it as a structured version of Wikipedia which can be accessed programmatically.</p><p>For example, if you want to display an input field on your website which allows people to pick their favourite musician, you could fire a Wikidata query (from your UI or backend) which gets a list of all musicians, and you can use this list to show a suggestion list. More interesting, however, is the additional logic you can apply while querying for musicians. For example, you can filter for folk rock musicians born after 1980 in the UK etc.</p><p>While exploring how to use WikiData, I found that there are two APIs which let us access Wikidata, each intended for different purposes.</p><blockquote>1. The “wbsearchentities” API</blockquote><p>This API is simple way of searching for entities using their labels or aliases. For example, if you would like to get all entities names ‘bond’, you can use the following GET query:</p><pre>curl &#39;https://www.wikidata.org/w/api.php?action=wbsearchentities&amp;search=bond&amp;format=json&amp;language=en&amp;uselang=en&amp;type=item&amp;limit=20&#39;</pre><p>This returns a list of Wikidata entities whose label(s) OR alias(es) contain the word Bond. You can customize the output returned using different url parameters (see the <a href="https://www.wikidata.org/w/api.php?action=help&amp;modules=wbsearchentities">docs</a>). Some of the important ones are:</p><ul><li>search : The text to search for</li><li>type : Type of entity to search for - item (default), property etc.</li><li>limit : Number of entities to fetch</li><li>continue : Offset to search from (useful for paginating the response)</li></ul><p>This API is useful for building suggestion dropdowns (The <a href="https://www.wikidata.org/wiki/Wikidata:Main_Page">official Wikidata page</a> uses it too for its search bar). However, it does not let us apply logical constraints when fetching for data. For example, in the above query, we cannot apply a filter for entities which are <a href="https://www.wikidata.org/wiki/Property:P31">instances of</a> the <a href="https://www.wikidata.org/wiki/Q5">Human</a> entity if we wanted to fetch only entities which refer to a person.</p><blockquote>2. The Wikidata SPARQL API</blockquote><p>This API lets you access Wikidata intelligently. You can formulate complex queries by specifying constraints on the entities and properties. For example, if you wanted to fetch all entities named Bond but only if they refer to human beings, you can use the following query:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c405fb8daf59be59311f76dc7268128/href">https://medium.com/media/8c405fb8daf59be59311f76dc7268128/href</a></iframe><p>The query can be tested on the <a href="https://query.wikidata.org/">Wikidata Query Service page</a>. Constraints are specified using the triples syntax:</p><pre>&lt;object&gt; &lt;relationship&gt; &lt;object&gt;</pre><p>We see 2 constraints in the above queries. Also, the Wikibase label service is used to get the names of the entities. For the official step-by-step Wikidata SPARQL tutorial, see <a href="https://www.wikidata.org/wiki/Wikidata:SPARQL_tutorial">this</a>. Also, there is a really good introductory video on <a href="https://www.youtube.com/watch?v=kJph4q0Im98">YouTube</a>.</p><p>You can formulate much more complicated queries. Many interesting queries with explanations can be found <a href="https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples">here</a> and <a href="https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries">here</a>. These show us how to perform sorting, filtering, working with dates etc.</p><p>The API can be used by firing simple GET requests to the endpoint:</p><pre><a href="https://query.wikidata.org/sparql">https://query.wikidata.org/sparql</a></pre><p>For example, a simple Javascript program to perform the above query will look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35193dcca97351e94873ffb9bb34fa7f/href">https://medium.com/media/35193dcca97351e94873ffb9bb34fa7f/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a678ee6d2968" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connecting MongoDB to Elasticsearch]]></title>
            <link>https://agg-shashank.medium.com/connecting-mongodb-to-elasticsearch-8a18d942f5?source=rss-396282b88d6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a18d942f5</guid>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[logstash]]></category>
            <category><![CDATA[nosql]]></category>
            <dc:creator><![CDATA[Shashank Aggarwal]]></dc:creator>
            <pubDate>Sat, 16 May 2020 23:01:51 GMT</pubDate>
            <atom:updated>2020-06-18T16:19:37.136Z</atom:updated>
            <content:encoded><![CDATA[<p>Since you are already reading this, I assume you know what Mongo and Elastic are, so let’s <a href="https://knowyourmeme.com/memes/the-wadsworth-constant">skip</a> to the main content.</p><p>There are a few blogs (such as <a href="https://code.likeagirl.io/5-different-ways-to-synchronize-data-from-mongodb-to-elasticsearch-d8456b83d44f">this</a> and <a href="https://www.digitalocean.com/community/tutorials/how-to-sync-transformed-data-from-mongodb-to-elasticsearch-with-transporter-on-ubuntu-16-04">this</a>) which discuss this. Some of the mentioned tools are fairly old, and no longer maintained. Some work only in batch mode, i.e., a one-time dump from Mongo to Elastic. I wanted to sync them in realtime, i.e, as soon as a new document is inserted into Mongo, it should also be inserted into an Elasticsearch index.</p><p>My guess for why these tools are not actively maintained is that since MongoDB now comes with better full text search features (such as <a href="https://docs.mongodb.com/manual/tutorial/control-results-of-text-search/">field-boosting</a>), so (at least for simple use cases) people end up using Mongo itself for their text search requirements. This was not the case for us because:</p><ol><li>Our data was relatively large in size (~10GB), and we had to perform full text search very frequently.</li><li>Elasticsearch is more feature rich. For example, it lets us prioritise recent content in the search results more intelligently (penalising old content using <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-decay">decay functions</a>) as opposed to a simple “sort by date”.</li></ol><p>The library I ended up using was <a href="https://rwynn.github.io/monstache-site/">Monstache</a>. It is a daemon which keeps the Elasticsearch database in sync with a MongoDB database. It works by monitoring the MongoDB <a href="https://docs.mongodb.com/manual/core/replica-set-oplog/">oplog</a> for any operation on the database. Since oplog is a feature only for MongoDB databases deployed as replica sets, Monstache does not work for standalone MongoDB instances. (I discuss a method for standalone MongoDB in the end)</p><p><strong>Step 1: Setting up monstache</strong></p><p>Monstache is a daemon. Where you choose to run it is up to you. We run it on the AWS EC2 instance which hosts our primary MongoDB instance. Of course, you can run it on a (small) dedicated server as well.</p><p>Get the latest monstache binary from <a href="https://github.com/rwynn/monstache/releases">here</a>. Monstache expects a single configuration file as a parameter. This was ours (short explanation follows):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d49c53efbd059c5e4d191bdc4c21f82/href">https://medium.com/media/9d49c53efbd059c5e4d191bdc4c21f82/href</a></iframe><p><strong>Authentication:</strong> Here, both the Mongo and Elastic authentication are basic username/password based, but Monstache also supports other types.</p><p><strong>Mapping from Mongo to Elastic: </strong>By default, Monstache inserts the documents into an Elasticsearch index named &lt;mongo-document-database&gt;.&lt;mongo-document-collection&gt;</p><p>This can be changed by specifying an <a href="https://rwynn.github.io/monstache-site/advanced/#index-mapping">index-mapping</a>.</p><p><strong>Custom logic: </strong>You might want to filter out some documents, or pick only a few fields to insert into Elasticsearch. A custom script, like the one above, is one way of doing that.</p><p><strong>Step 2: Running monstache</strong></p><pre>./monstache -f monstache.toml</pre><p>If you are running this on a remote machine, you will want to keep it running after you log out as well. Use this instead:</p><pre>nohup ./monstache -f monstache.toml &amp;</pre><p>This will run it in the background, and the output will be written to a file <em>nohup.out</em></p><pre>$ tail -f nohup.out <br>Sending to Elastic :  85xc5z8f33ul4js<br>Sending to Elastic :  2p1ruc42ya8o3ko<br>Sending to Elastic :  muw6lmtzwgr4ivr<br>Sending to Elastic :  k6cdbf505qzy9ce<br>Sending to Elastic :  8p0vk79n7akr5f6<br>...</pre><p>That’s it! Check your Elasticsearch database for the documents, and you should find them there.</p><p><strong>Step 3 (Optional): Replicating this setup locally</strong></p><p>It is possible that you want this Mongo-to-Elastic logic on your local dev setup as well in. In case your local MongoDB setup is a replica set, the above approach should work.</p><p>But more likely, you use the standalone deployment method for MongoDB on you local dev machine. In that case, we need another approach. I use <a href="https://www.elastic.co/logstash">Logstash</a> for this. This is a tool built by Elastic (the company behind Elasticsearch), and lets you connect different sources of data.</p><p>This is a much more powerful and general tool. But for our case, it works similar to Monstache. We specify a source of data, our custom transformations, and an output ‘sink’ in a configuration file, and logstash does the rest. Here is mine:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f0df728fe3621ea30fe3be42d20b07f/href">https://medium.com/media/2f0df728fe3621ea30fe3be42d20b07f/href</a></iframe><p>Fairly self-explanatory. Notably, we have used the <a href="https://github.com/phutchins/logstash-input-mongodb"><em>MongoDB input plugin</em></a> for Logstash. This plugin checks for MongoDB updates every 5 seconds, and pushes them to Elasticsearch.</p><p>This approach can, obviously, be used for your production setup as well. But I found it to be very CPU-intensive. Also, I found Monstache to be an amazing tool — it’s well documented, (very) well maintained and overall just very easy to use (all attributes of a good open source library :)).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a18d942f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A blockchain solution to the Aadhar ?]]></title>
            <link>https://agg-shashank.medium.com/a-blockchain-solution-to-the-aadhar-4f91f2a5ca31?source=rss-396282b88d6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f91f2a5ca31</guid>
            <category><![CDATA[aadhaar]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[india]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Shashank Aggarwal]]></dc:creator>
            <pubDate>Thu, 10 Aug 2017 14:05:43 GMT</pubDate>
            <atom:updated>2017-08-11T19:31:46.127Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Gn-bhAkC0ZG3uKE5MqXWQ.jpeg" /></figure><p>The recent leak of Aadhar data (Aadhar number and other sensitive information) has brought back into focus the privacy and security issues with the program. There are a few concerns people talk about pertaining to Aadhar:</p><p><strong>Multiple authentications without consent: </strong>A consumer is expected to provide his personal data (demographic/biometric) along with his Aadhar number for authenticating with private providers (telecom, banks etc.). Using this information, the entity tries to authenticate the user to determine if he is indeed the rightful owner of the Aadhar number.</p><p>There have been cases of biometrics being stored by the agency, and being repeatedly used to authenticate the holder. An alternative could be that the holder’s consent is required for every authentication request.</p><p><strong>Unnecessary access to data: </strong>A simple authentication of a person by a telecom operator requires the user to provide his personal data to the operator. The operator then authenticates the user by calling the UIDAI services. While this is acceptable in case of KYC (such as banks) where the data is required by the entity, why do telecom operators need to know personal data ? The user should be able to authenticate himself with UIDAI, and merely provide the proof of authentication to the service agency.</p><p>Of course, these worries become alarming only if the Aadhar User Agency or AUA (entities seeking Authentication through UIDAI) indulges in malpractices such as sharing user data without consent, combining databases with other AUAs etc. Eventually, as long as there are no strict laws restricting the use of Aadhar data, one should assume that data collected by these organisations is not private.</p><p>Blockchain technology provides a sound solution to the problem of authentication without compromising on privacy. Generally, a blockchain is a public database, to which anyone can write data. This data can be of any form . A popular example is the <strong>Bitcoin</strong> blockchain, where users can add transactions to the blockchain, transferring a certain amount of Bitcoin currency to another user. The most notable characteristics of a blockchain are immutability and public access. Once some data has been written to the blockchain, it cannot be erased/changed. Furthermore, all the data is publicly viewable.</p><p>This fits particularly well for an identity verification system. Every entity which wants to authenticate a user/customer has to publicly request for it. Also, every request for authentication should be approved by the user, and only then forwarded to the government. Furthermore, the user should provide his data directly to the government.</p><p>The solution proposed is as follows:</p><ol><li>The AUA adds an authentication request to the blockchain. It specifies the user it wants to authenticate, and the purpose for which authentication is required.</li><li>The user approves the request, then adds his personal data to the blockchain, encrypted such that only the government can decrypt it. (This provision of data can happen off the blockchain as well — on a government website for example)</li><li>The government then looks at the request from the AUA, and the data provided by the user, and calls its internal services to verify if the data provided by the user indeed corresponds to him/her.</li><li>The government appropriately marks the request as rejected/approved.</li><li>The AUA then queries the blockchain to see if its request has been approved by the government.</li></ol><p>All the steps above which involve writing to the database are publicly accessible. Thus, the request from the AUA, the approval by the user, and the approval by the government — all are verifiable at any later point in time.</p><p>If this entire behaviour can be codified, and the code itself can me made immutable, we can be assured that no human intervention can change/game the system. <strong>Ethereum</strong> can help us here.</p><h3>Ethereum</h3><p>Ethereum is public blockchain. It has its own currency (ether). However, its strength lies in its ability to store code. Pieces of code (called <strong>smart contracts</strong>) can be stored on the blockchain. These contracts can be made to solve any particular use case. They are publicly accessible, and the functions defined in these can be called by anyone on the ethereum network. A few points to keep in mind:</p><ol><li>Every user on the Ethereum network is given a unique public address.</li><li>People can transact (exchange ether) with each other using their public addresses.</li><li>Additionally, every smart contract is also similar to a user — it has its own public address. People can send ether to this smart contract. The contract can send ether to others. In effect, a contract is like any other human, except that its behaviour is driven by code.</li><li>A contract exposes certain functions/methods. Other users can call these function. Each of these calls is stored on the blockchain (like any other transaction). These calls cause the contract to behave in certain predefined ways — for example send ether to someone, update its own program data etc.</li></ol><p>Keeping this in mind, have a look at this contract, which codifies the behaviour stated above.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62aaac0972cc77106b59694e64b23b85/href">https://medium.com/media/62aaac0972cc77106b59694e64b23b85/href</a></iframe><p>The notable advantages of this system:</p><ol><li>User approval is explicitly required for every request an AUA raises. The government cannot directly approve the authentication request.</li><li>Only the govt. can access the data provided by the user. This data can be encrypted/decrypted using symmetric private keys, which are shared only between the govt. and the user.</li></ol><p>The code (and all the requests made to it) are public, and can never be erased owing to the nature of the blockchain technology. This differs greatly from code which is locked in servers inaccessible to public scrutiny.</p><p>This transparency can help restore some of the faith lost in authentication programmes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f91f2a5ca31" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>