<?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: Aniketh Deshpande</title>
    <description>The latest articles on DEV Community by Aniketh Deshpande (@anikethsdeshpande).</description>
    <link>https://dev.to/anikethsdeshpande</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%2F212621%2F92bf2932-4c1c-4ae4-87c2-96232ff403dc.jpeg</url>
      <title>DEV Community: Aniketh Deshpande</title>
      <link>https://dev.to/anikethsdeshpande</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anikethsdeshpande"/>
    <language>en</language>
    <item>
      <title>Predicate Pushdown - Understanding Practically With An Example</title>
      <dc:creator>Aniketh Deshpande</dc:creator>
      <pubDate>Wed, 17 Apr 2024 19:42:28 +0000</pubDate>
      <link>https://dev.to/anikethsdeshpande/predicate-pushdown-understanding-practically-with-an-example-4b51</link>
      <guid>https://dev.to/anikethsdeshpande/predicate-pushdown-understanding-practically-with-an-example-4b51</guid>
      <description>&lt;p&gt;What is predicate pushdown?&lt;/p&gt;

&lt;p&gt;The immediate theoretical answer that we get on searching is&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Predicate pushdown is a query optimisation technique used in database technologies&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Okay, I got to know that it is an optimisation technique. But I still did not understand...&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How is the optimisation happening? 🤨&lt;/li&gt;
&lt;li&gt;What is predicate? 🤔&lt;/li&gt;
&lt;li&gt;What exactly is the meaning of pushed down here? 🤷‍♂️&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I'm sure since you are also reading this article, even you have these questions in mind!&lt;/p&gt;

&lt;p&gt;Now, lets explore this interesting topic practically in &lt;strong&gt;&lt;em&gt;PySpark&lt;/em&gt;&lt;/strong&gt; using &lt;code&gt;explain()&lt;/code&gt;&lt;br&gt;
(Similar phenomenon could be observed in relational databases as well)&lt;/p&gt;

&lt;p&gt;1] Reading a csv file containing employee information.&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;emp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;spark&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;csv&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;\
                &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;option&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;header&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;\
                &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data/employee.csv&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;emp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fppxfeaejoac8noucyd86.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%2Fppxfeaejoac8noucyd86.png" alt="df.show" width="700" height="476"&gt;&lt;/a&gt;&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;emp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;explain&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;formatted&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fxg2ushs3wglcaltw18wk.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%2Fxg2ushs3wglcaltw18wk.png" alt="pyspark explain read df" width="800" height="148"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, step (1) is related to read csv file&lt;/p&gt;

&lt;p&gt;2] Lets do a group by and get number of employees on each department&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;df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;emp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;groupBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;deptID&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;count&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fxqawodk4tq9qwuy14eu5.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%2Fxqawodk4tq9qwuy14eu5.png" alt="emp group by" width="284" height="278"&gt;&lt;/a&gt;&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;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;explain&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;formatted&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fjehpma6xwkaybwow9kby.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%2Fjehpma6xwkaybwow9kby.png" alt="df explain" width="800" height="521"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, step (2) is related to &lt;code&gt;group by&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;3] Lets filter data for only dept number 10&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;dept_10&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;deptID&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;dept_10&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fz0a88h1wfr5ccnexkdaz.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%2Fz0a88h1wfr5ccnexkdaz.png" alt="Image description" width="348" height="184"&gt;&lt;/a&gt;&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;dept_10&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;explain&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;formatted&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2F5ma0nok0jxtp0zuky4x0.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%2F5ma0nok0jxtp0zuky4x0.png" alt="Image description" width="800" height="599"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, we can see that step (2) is filtering and step (3) is grouping. &lt;/p&gt;

&lt;p&gt;Now here is the catch, &lt;br&gt;
Ideally if we go by the sequence of operations, grouping should be done first and then filtering. &lt;/p&gt;

&lt;p&gt;However, the optimiser does filtering first and then grouping, because grouping is an expensive operation and it is optimal to filter first and then group data.&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%2Fiywjb9ic2nu0l5ue64m7.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%2Fiywjb9ic2nu0l5ue64m7.png" alt="Image description" width="544" height="268"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the physical plan we see that filtering (&lt;code&gt;predicate&lt;/code&gt;) is pushed down with respect to grouping. That is why it is called &lt;code&gt;push down&lt;/code&gt; ! &lt;/p&gt;

</description>
      <category>spark</category>
      <category>optimisation</category>
      <category>sql</category>
      <category>interview</category>
    </item>
    <item>
      <title>Write Through</title>
      <dc:creator>Aniketh Deshpande</dc:creator>
      <pubDate>Fri, 22 Mar 2024 13:06:39 +0000</pubDate>
      <link>https://dev.to/anikethsdeshpande/write-through-81n</link>
      <guid>https://dev.to/anikethsdeshpande/write-through-81n</guid>
      <description>&lt;p&gt;Write through cache is a simple to implement caching mechanism.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Here the newly arrived data is written into cache and as well as persisted into the disk or a database. Atomicity is maintained.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are two ways to implement it:&lt;br&gt;
1] The application writes data to cache and database simultaneously&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%2Fmz9ls68gioad30eo5d0v.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%2Fmz9ls68gioad30eo5d0v.png" alt="Write through cache" width="800" height="511"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2] The application writes data to cache and then the cache writes the data into the database.&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%2Fy577t78bpgorm1dqudns.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%2Fy577t78bpgorm1dqudns.png" alt="Write through cache 2" width="800" height="209"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Advantages:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Simple to implement.&lt;/li&gt;
&lt;li&gt;Faster response times.&lt;/li&gt;
&lt;li&gt;Data integrity because of atomic nature of write operation. &lt;/li&gt;
&lt;li&gt;Lower latency for subsequent reads.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Disadvantages:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Cache pollution: Since every time the data is filled into cache, it can get filled with less frequently read data and more cache eviction which could introduce some latency.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Not suitable for write intensive scenarios as the write operations are slower compared to other methods because data needs to be written in cache as well as persistent storage everytime.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>cache</category>
      <category>redis</category>
      <category>systemdesign</category>
      <category>writepolicy</category>
    </item>
    <item>
      <title>Database Caching Strategies</title>
      <dc:creator>Aniketh Deshpande</dc:creator>
      <pubDate>Fri, 22 Mar 2024 12:43:08 +0000</pubDate>
      <link>https://dev.to/anikethsdeshpande/cache-write-policies-419b</link>
      <guid>https://dev.to/anikethsdeshpande/cache-write-policies-419b</guid>
      <description>&lt;p&gt;We often face high latencies while fetching data from Database and are unable to meet SLA. Caching is one of the solutions to implement after DB query and table optimisations. &lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;Cache&lt;/strong&gt; is used to store the data so that it can be delivered faster to the client as compared to persistent systems like database or disk.&lt;/p&gt;

&lt;p&gt;Popular caching tools are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://redis.io/" rel="noopener noreferrer"&gt;Redis&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://memcached.org/" rel="noopener noreferrer"&gt;Memcached&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are multiple ways in which data can be written into and read from the cache. Let us explore the most prominently used methods or policies.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cache Aside
&lt;/h2&gt;

&lt;p&gt;Cache Aside or Lazy Loading is one of the cache write policies or strategies.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In cache aside method, the application is responsible for storing data into cache.&lt;/li&gt;
&lt;li&gt;When the client sends request to the application, it looks for data in the cache.&lt;/li&gt;
&lt;li&gt;If the data is found in the cache it is called as &lt;em&gt;cache-hit&lt;/em&gt;. The data is fetched from cache and returned to client.&lt;/li&gt;
&lt;li&gt;However, if the data is not found in the cache, also called as &lt;em&gt;cache-miss&lt;/em&gt;, the application queries for data in the database, writes the data into cache and sends the response to the client.&lt;/li&gt;
&lt;li&gt;Since we store data in cache only when it is necessary, this strategy is also called as Lazy-Loading.&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%2Flh6koyxc7792iu568usl.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%2Flh6koyxc7792iu568usl.png" alt="Cache Aside - Write Strategy" width="538" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Cost effective&lt;/em&gt; because, only the frequently accessed data is stored into cache.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Disadvantages:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The response time can be slow when there is cache miss, because, it involves many i/o operations to fetch data from DB and store it in cache.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;In case the system can tolerate an initial delay and the same data is to be fetched repeatedly, then this mechanism works best.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Write through
&lt;/h2&gt;

&lt;p&gt;Write through cache is a simple to implement caching mechanism.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Here the newly arrived data is written into cache and as well as persisted into the disk or a database. Atomicity is maintained.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are two ways to implement it:&lt;br&gt;
1] The application writes data to cache and database simultaneously&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%2Fmz9ls68gioad30eo5d0v.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%2Fmz9ls68gioad30eo5d0v.png" alt="Write through cache" width="800" height="511"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2] The application writes data to cache and then the cache writes the data into the database.&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%2Fy577t78bpgorm1dqudns.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%2Fy577t78bpgorm1dqudns.png" alt="Write through cache 2" width="800" height="209"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Advantages:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Faster response times.&lt;/li&gt;
&lt;li&gt;Data integrity because of atomic nature of write operation. &lt;/li&gt;
&lt;li&gt;Lower latency for subsequent reads.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Disadvantages:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Cache pollution: Since every time the data is filled into cache, it can get filled with less frequently read data and more cache eviction which could introduce some latency.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Not suitable for write intensive scenarios as the write operations are slower compared to other methods because data needs to be written in cache as well as persistent storage everytime.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;In case the system cannot tolerate an initial delay and the writes are infrequent, then this mechanism works best. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Also if the number of records to be cached is also fixed, then this approach can provide the best of the results.&lt;/p&gt;

&lt;blockquote&gt;
&lt;/blockquote&gt;

&lt;p&gt;Thank you :)&lt;/p&gt;

</description>
      <category>gratitude</category>
    </item>
    <item>
      <title>Cache Aside</title>
      <dc:creator>Aniketh Deshpande</dc:creator>
      <pubDate>Fri, 22 Mar 2024 12:41:36 +0000</pubDate>
      <link>https://dev.to/anikethsdeshpande/cache-aside-1ioa</link>
      <guid>https://dev.to/anikethsdeshpande/cache-aside-1ioa</guid>
      <description>&lt;p&gt;Cache Aside or Lazy Loading is one of the cache write policies or strategies.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In cache aside method, the application is responsible for storing data into cache.&lt;/li&gt;
&lt;li&gt;When the client sends request to the application, it looks for data in the cache.&lt;/li&gt;
&lt;li&gt;If the data is found in the cache it is called as &lt;em&gt;cache-hit&lt;/em&gt;. The data is fetched from cache and returned to client.&lt;/li&gt;
&lt;li&gt;However, if the data is not found in the cache, also called as &lt;em&gt;cache-miss&lt;/em&gt;, the application queries for data in the database, writes the data into cache and sends the response to the client.&lt;/li&gt;
&lt;li&gt;Since we store data in cache only when it is necessary, this strategy is also called as Lazy-Loading.&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%2Flh6koyxc7792iu568usl.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%2Flh6koyxc7792iu568usl.png" alt="Cache Aside - Write Strategy" width="538" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Advantages:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;The implementation is simple.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Disadvantages:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;The response time can be slow when there is cache miss, because, it involves many io operations to fetch data from DB and store it in cache.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>gratitude</category>
      <category>tailwindcss</category>
      <category>opensource</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Shallow Copy Vs Deep Copy</title>
      <dc:creator>Aniketh Deshpande</dc:creator>
      <pubDate>Sat, 29 Oct 2022 12:57:16 +0000</pubDate>
      <link>https://dev.to/anikethsdeshpande/shallow-copy-vs-deep-copy-56jf</link>
      <guid>https://dev.to/anikethsdeshpande/shallow-copy-vs-deep-copy-56jf</guid>
      <description>&lt;p&gt;In our day to day development tasks, we come across the need to copy objects and perform various operations.&lt;/p&gt;

&lt;p&gt;Python provides two important functions in the &lt;strong&gt;copy&lt;/strong&gt; library - &lt;em&gt;copy&lt;/em&gt; and &lt;em&gt;deepcopy&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Let us understand the difference between the two and their respective use cases.&lt;/p&gt;

&lt;h3&gt;
  
  
  Shallow Copy - copy.copy(obj)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;It makes a copy of the obj at the surface level. &lt;/li&gt;
&lt;li&gt;It copies all the contents of the obj.&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%2Ferp0i8785js06ednujn9.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%2Ferp0i8785js06ednujn9.png" alt="copy.copy()" width="752" height="210"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;However, the point to be noted here is that, in case the contents of x are mutable, then, y has reference to the contents of x. Any modification to the contents of x would be reflected in y as well.&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%2F67ef2wud6bu5y3rq9ve7.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%2F67ef2wud6bu5y3rq9ve7.png" alt="shallow copy" width="800" height="170"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example we see that modifying the contents of x[1], also modified the contents of y[1].&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%2F3o45byvy1gst3yy8q5tw.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%2F3o45byvy1gst3yy8q5tw.png" alt="shallow copy" width="800" height="151"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Similarly, we see that modifying the contents of y, also modified the contents of x.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deep Copy - copy.deepcopy(obj)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Deepcopy copies the object recursively. Recursively means, it copies the contents of the object and not merely its reference.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;So we should use deep copy in case we need an independent copy of the contents of the obj.&lt;/p&gt;&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%2F53buud6tqel6affms9k9.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%2F53buud6tqel6affms9k9.png" alt="Deepcopy" width="726" height="208"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In deepcopy, any changes to the contents of x do not effect y, unlike shallow copy.&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%2Fn23a8du7apog6p8shsfx.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%2Fn23a8du7apog6p8shsfx.png" alt="Deepcopy" width="774" height="172"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Copying objects properly is a very important &lt;em&gt;basic python concepts&lt;/em&gt;. This knowledge helps in building error free code wrt copying objects.&lt;/p&gt;

&lt;p&gt;Thank you&lt;br&gt;
Aniketh Deshpande&lt;/p&gt;

</description>
      <category>python</category>
      <category>deepcopy</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Dead Letter Queue</title>
      <dc:creator>Aniketh Deshpande</dc:creator>
      <pubDate>Sun, 23 Oct 2022 11:50:55 +0000</pubDate>
      <link>https://dev.to/anikethsdeshpande/dead-letter-queue-1ml2</link>
      <guid>https://dev.to/anikethsdeshpande/dead-letter-queue-1ml2</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is going to be a very short introduction to dead letter queues. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  What is a dead letter queue??
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Dead letter queues are messages queues specifically deployed to holding messages that could not be delivered to their intended queues.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Messages sometimes fail to get delivered to their intended queues as they might be unavailable or the queue is full.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Popular message queue tools that support or do not support DLQ:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AWS SQS (Simple Queue Service) supports DLQ.&lt;/li&gt;
&lt;li&gt;RabbitMQ (free and open source) also supports DLQ.&lt;/li&gt;
&lt;li&gt;Redis does not support DLQ.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;p&gt;Thanks for reading :)&lt;br&gt;
DLQ is a very important component of a scalable and resilient software architecture. This article only provides an introduction to the concept and helps readers with useful links.&lt;/p&gt;

&lt;p&gt;Following are some of the useful resources that give more indepth information.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://aws.amazon.com/about-aws/whats-new/2021/12/amazon-sqs-dead-letter-queue-management-experience-queues/" rel="noopener noreferrer"&gt;https://aws.amazon.com/about-aws/whats-new/2021/12/amazon-sqs-dead-letter-queue-management-experience-queues/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/antirez/disque#dead-letter-queue" rel="noopener noreferrer"&gt;https://github.com/antirez/disque#dead-letter-queue&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/13824879/how-to-resend-from-dead-letter-queue-using-redis-mq" rel="noopener noreferrer"&gt;https://stackoverflow.com/questions/13824879/how-to-resend-from-dead-letter-queue-using-redis-mq&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I request the readers of this post to kindly add more helpful URLs in the comment section, or add your experiences using a DLQ in a real world project. I believe that would help beginners get even better idea about how to use this in their projects.&lt;/p&gt;

&lt;p&gt;Thank You&lt;br&gt;
Aniketh Deshpande&lt;/p&gt;

</description>
      <category>messagequeue</category>
      <category>systemdesign</category>
      <category>aws</category>
      <category>rabbitmq</category>
    </item>
    <item>
      <title>Change Data Capture - PostgreSQL</title>
      <dc:creator>Aniketh Deshpande</dc:creator>
      <pubDate>Sat, 22 Oct 2022 14:58:18 +0000</pubDate>
      <link>https://dev.to/anikethsdeshpande/change-data-capture-postgresql-bi8</link>
      <guid>https://dev.to/anikethsdeshpande/change-data-capture-postgresql-bi8</guid>
      <description>&lt;p&gt;&lt;strong&gt;Change Data Capture&lt;/strong&gt; is the concept of recording the changes in the database table fields.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It is very helpful in use cases where we want to track creation, updation, deletion of records in the table.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We might want to use this information to make changes in other databases or notify customers or notify other services.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Example: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Save a copy of this data in a warehouse post transform.&lt;/li&gt;
&lt;li&gt;Trigger notification service to notify users about this change.&lt;/li&gt;
&lt;li&gt;Cache the data.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  CDC In Postgres
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Using &lt;strong&gt;Notify/Listen&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;NOTIFY&lt;/code&gt; provides a mechanism for interprocess communication between the database and the service that is &lt;code&gt;LISTEN&lt;/code&gt;ing to this notification channel.&lt;/li&gt;
&lt;li&gt;One or more services could be listening to this notification channel.&lt;/li&gt;
&lt;li&gt;Name of this channel is usually the name of the database. However the user is free to set suitable names for these channels.&lt;/li&gt;
&lt;li&gt;Any change in the table is captured by the DB and a trigger is initiated, which calls a function that formats the message to notify.&lt;/li&gt;
&lt;li&gt;This usually contains the table name and the payload string.&lt;/li&gt;
&lt;li&gt;The listening server registers to the channel and gets the message from the DB.&lt;/li&gt;
&lt;li&gt;The service can then use this message and perform operations on it.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h4&gt;
  
  
  Pros:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Simple to implement. Use a trigger and a function to notify. Implement a listen service.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Cons:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Weak reliability. There is always a risk of loss of message especially when the listening service is down. Messages in the queue do not persist.&lt;/li&gt;
&lt;/ul&gt;




&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Using &lt;strong&gt;Debezium&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Debezium is an open source tool used for capturing changes in the database tables based on the WAL (write ahead log).&lt;/li&gt;
&lt;li&gt;The tool provides connectors to connect to a variety of databases.&lt;/li&gt;
&lt;li&gt;The &lt;em&gt;source connector&lt;/em&gt; is used to capture changes in the source database.&lt;/li&gt;
&lt;li&gt;The &lt;em&gt;sync connector&lt;/em&gt; is used to sync data directly in the destination database. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h4&gt;
  
  
  Pros:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The changes are persistent as they can be streamed to kafka. Hence highly reliable.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Cons:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Debezium does not take into account changes in the schema, users need to update the schema changes. Otherwise there would be data loss.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Thank you&lt;br&gt;
Aniketh Deshpande&lt;/p&gt;

</description>
      <category>debezium</category>
      <category>postgres</category>
      <category>cdc</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>DB Locking - Why and How?</title>
      <dc:creator>Aniketh Deshpande</dc:creator>
      <pubDate>Fri, 21 Oct 2022 18:39:15 +0000</pubDate>
      <link>https://dev.to/anikethsdeshpande/db-locking-why-and-how-2c2p</link>
      <guid>https://dev.to/anikethsdeshpande/db-locking-why-and-how-2c2p</guid>
      <description>&lt;p&gt;If you have sent concurrent requests to your DB to modify its contents, you would have come across a phenomenon called &lt;strong&gt;The Double Booking Problem!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Double Booking Problem arises when &lt;strong&gt;&lt;em&gt;two or more&lt;/em&gt;&lt;/strong&gt; threads read the same data point and one thread incorrectly overwrites the changes done by another thread resulting in inconsistency.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lets see an example to get better understanding of it.&lt;/li&gt;
&lt;li&gt;Suppose its a bus booking application. &lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;User 1 and User 2, both read Seat_21 as available.&lt;/li&gt;
&lt;li&gt;User 1 books the seat. However User 2 is unaware of this as he has read Seat_21 is available.&lt;/li&gt;
&lt;li&gt;User 2 also books the seat. Now the seat info is overwritten and the seat is allotted to User 2.&lt;/li&gt;
&lt;li&gt;Due to this phenomenon of double time booking of resources, it is named as &lt;em&gt;The Double Booking Problem!&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Following flow diagram gives clear idea about it.&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%2Fiux83lrregifjdthinrc.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%2Fiux83lrregifjdthinrc.png" alt="Double Booking Problem Flowchart" width="800" height="568"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In order to avoid this, we need to use locking.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Locking in DynamoDB
&lt;/h3&gt;

&lt;p&gt;Let us see how we can lock dynamodb objects.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Optimistic Locking
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The spotlight feature of optimistic locking is, it does not have a lock as such. Instead a &lt;strong&gt;version number&lt;/strong&gt; is attached to the record and it is incremented whenever the record is updated.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Multiple users are allowed to read the document or record.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When the users try to commit their changes, the change related to the first request is accepted as the version numbers match in the record and in the commit request.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Subsequent users trying to commit their changes are sent a &lt;em&gt;Validation Exception&lt;/em&gt;!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Based on this, the users can sync the updated record and make their changes and retry committing the changes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Therefore, the double booking problem is eliminated.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. Pessimistic Locking
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;In pessimistic locking mechanism, &lt;strong&gt;Locks&lt;/strong&gt; are implemented. The record that is being updated is locked when a user starts a transaction.&lt;/li&gt;
&lt;li&gt;Since the record is locked, the other users trying to update the record are notified that the record is locked and the read also fails.&lt;/li&gt;
&lt;li&gt;This mechanism although equally effective, has an overhead of implementing locks.&lt;/li&gt;
&lt;li&gt;Therefore, the double booking problem is eliminated.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Thanks for reading this blog.&lt;br&gt;
Aniketh Deshpande&lt;br&gt;
India&lt;/p&gt;

</description>
      <category>database</category>
      <category>locking</category>
      <category>systemdesign</category>
      <category>dynamodb</category>
    </item>
    <item>
      <title>TimescaleDB Tablespaces</title>
      <dc:creator>Aniketh Deshpande</dc:creator>
      <pubDate>Fri, 21 Oct 2022 04:59:45 +0000</pubDate>
      <link>https://dev.to/anikethsdeshpande/timescaledb-tablespaces-4dh3</link>
      <guid>https://dev.to/anikethsdeshpande/timescaledb-tablespaces-4dh3</guid>
      <description>&lt;h3&gt;
  
  
  Tablespace
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Tablespace&lt;/strong&gt; is a storage location where the actual data is stored. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The tuples belonging to the same table could be stored in different tablespaces.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tablespaces are mainly used to separately store data of different priority in different kind of disk.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Example: Data of active users, or recent active customers can be stored in &lt;em&gt;fast disk types&lt;/em&gt; like ssd or flash. Data that is old and unused frequently or archived, can be stored in a &lt;em&gt;less expensive and slower&lt;/em&gt; data storage like HDD. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  TimescaleDB
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;TimescaleDB is an open source time series database. It is extends PostgreSQL and supports most of the commands of postgres.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Docker Image:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker pull timescale/timescaledb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;TimescaleDB has a concept of hypertables and chunks. Hypertables are Postgresql tables, that partition the data into chunks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The chunks are created based on primarily the time field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The chunks older than certain date can be moved to a slow disk like HDD and the latest data which would be heavily used can be used in a fast disk like SSD and Flash.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The concept of &lt;em&gt;tablespaces&lt;/em&gt; helps in here.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;TSDB code to move chunks:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT move_chunk(
  chunk =&amp;gt; '_timescaledb_internal._hyper_1_4_chunk',
  destination_tablespace =&amp;gt; 'tablespace_2',
  index_destination_tablespace =&amp;gt; 'tablespace_3',
  reorder_index =&amp;gt; 'conditions_device_id_time_idx',
  verbose =&amp;gt; TRUE
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For detailed information, use the following link: &lt;a href="https://legacy-docs.timescale.com/v1.7/api#move_chunk" rel="noopener noreferrer"&gt;https://legacy-docs.timescale.com/v1.7/api#move_chunk&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  AWS Volumes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If the TSDB instance is hosted in a kubernetes cluster in AWS, the TSDB pod would be provided with an AWS Volume for persistent storage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;AWS supports the following volume classes. Based on speed and cost requirements, we can select the appropriate volumes for TSDB tablespaces.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;AWS volume types: &lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volume-types.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volume-types.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Thank you for reading the blog :) &lt;br&gt;
Aniketh Deshpande&lt;/p&gt;

</description>
      <category>timescaledb</category>
      <category>tablespace</category>
      <category>scaling</category>
      <category>aws</category>
    </item>
    <item>
      <title>Redis Timeseries</title>
      <dc:creator>Aniketh Deshpande</dc:creator>
      <pubDate>Thu, 20 Oct 2022 19:00:04 +0000</pubDate>
      <link>https://dev.to/anikethsdeshpande/redis-timeseries-4bnm</link>
      <guid>https://dev.to/anikethsdeshpande/redis-timeseries-4bnm</guid>
      <description>&lt;p&gt;Redis is an amazing tool to cache data. It supports different data types to help us cache different kinds of data.&lt;/p&gt;

&lt;p&gt;Following are the the data types supported as of Redis 7.0&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Strings&lt;/li&gt;
&lt;li&gt;Hashes&lt;/li&gt;
&lt;li&gt;Lists&lt;/li&gt;
&lt;li&gt;Sets&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sorted Sets&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Timeseries&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this article, we shall focus mainly on caching timeseries data in redis.&lt;/p&gt;

&lt;p&gt;We can cache timeseries data in the following ways:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Using the Redis-Timeseries extention&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Save data using &lt;code&gt;ADD KEY Timestamp Record&lt;/code&gt;&lt;br&gt;
where, Key is the name of the timeseries.&lt;br&gt;
Timestamp is the field used for sorting the elements.&lt;br&gt;
Record is the field representing the value at the given timestamp.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fetch records using &lt;code&gt;range&lt;/code&gt; command. &lt;code&gt;RANGE KEY FROM_TS TO_TS&lt;/code&gt; where from_ts and to_ts represent the upper bound and lower bound of the timestamp in the search space.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;NOTE: the record field is of type decimal. It supports only numbers.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Therefore, it is very helpful for saving single value records and not lists or maps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Example: stock values, moisture in soil etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;However it is not possible to save lists or tuples.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In that case, we can make use of Sorted Sets.&lt;/p&gt;


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

&lt;p&gt;&lt;strong&gt;2. Sorted Sets&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ZADD KEY Timestamp RECORD&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Here, zadd is used to save data in sorted sets. Key is the series name. Timestamp is the field used for sorting. Record can be of type string. Hence we can save json strings in the record field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To fetch data from sorted sets, use command &lt;code&gt;ZRANGE FROM_TS TO_TS BYSCORE=TRUE&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use &lt;code&gt;by_score&lt;/code&gt; to get data based on timestamp and not index.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Docker Image For Redis Timeseries
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;docker pull redislabs/redistimeseries&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Link: &lt;a href="https://hub.docker.com/r/redislabs/redistimeseries" rel="noopener noreferrer"&gt;https://hub.docker.com/r/redislabs/redistimeseries&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Thank you for reading the blog. Please suggest improvements and like the blog.&lt;/p&gt;

&lt;p&gt;Aniketh Deshpande&lt;/p&gt;

</description>
      <category>redis</category>
      <category>timeseries</category>
      <category>cache</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>ML Ops</title>
      <dc:creator>Aniketh Deshpande</dc:creator>
      <pubDate>Sat, 10 Oct 2020 02:54:07 +0000</pubDate>
      <link>https://dev.to/anikethsdeshpande/ml-ops-31mc</link>
      <guid>https://dev.to/anikethsdeshpande/ml-ops-31mc</guid>
      <description>&lt;p&gt;MLOps is an emerging field in the teck world. As the name suggests it's a combination of machine learning and devops. MLOps mainly focuses on fast and efficient delivery of machine learning models. &lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>devops</category>
      <category>mlops</category>
    </item>
  </channel>
</rss>
