<?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: Hassan Zahar Rifat</title>
    <description>The latest articles on DEV Community by Hassan Zahar Rifat (@hzahar).</description>
    <link>https://dev.to/hzahar</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%2F786118%2Fc6997899-a7db-4daa-8f8b-c5ab17702705.jpeg</url>
      <title>DEV Community: Hassan Zahar Rifat</title>
      <link>https://dev.to/hzahar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hzahar"/>
    <language>en</language>
    <item>
      <title>Bloom Filters: The Data Structure That's Wrong on Purpose (and Why That's Genius)</title>
      <dc:creator>Hassan Zahar Rifat</dc:creator>
      <pubDate>Mon, 08 Jun 2026 15:38:03 +0000</pubDate>
      <link>https://dev.to/hzahar/bloom-filters-the-data-structure-thats-wrong-on-purpose-and-why-thats-genius-44e8</link>
      <guid>https://dev.to/hzahar/bloom-filters-the-data-structure-thats-wrong-on-purpose-and-why-thats-genius-44e8</guid>
      <description>&lt;p&gt;&lt;em&gt;How databases, browsers and CDNs answer "have I seen this before?" using a fraction of the memory — by being wrong in exactly one safe direction.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Picture a sign-up form. You type a username, and &lt;em&gt;before&lt;/em&gt; you even finish, the field flashes red: &lt;strong&gt;"Already taken."&lt;/strong&gt; Instant. No spinner.&lt;/p&gt;

&lt;p&gt;Somewhere behind that, a system just answered the question &lt;em&gt;"have we seen this string before?"&lt;/em&gt; against tens of millions of existing usernames — and it did it without querying the database, without loading a list into memory, and in roughly the time it takes a single CPU instruction to run.&lt;/p&gt;

&lt;p&gt;It pulled that off with a data structure that has a strange, almost offensive property: &lt;strong&gt;it's allowed to be wrong.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Not randomly wrong. Wrong in exactly one direction, in a way you can mathematically bound, in exchange for using a fraction of the memory a normal set would. That trade is the whole trick, and once you see it you'll start noticing Bloom filters everywhere — in your database, your CDN, your browser, your favorite key-value store.&lt;/p&gt;

&lt;p&gt;Let's build one from scratch.&lt;/p&gt;




&lt;h2&gt;
  
  
  First, why the obvious solutions fall apart
&lt;/h2&gt;

&lt;p&gt;The question is dead simple: &lt;strong&gt;is element &lt;code&gt;x&lt;/code&gt; in set &lt;code&gt;S&lt;/code&gt;?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You already know how to answer this. A hash set. &lt;code&gt;O(1)&lt;/code&gt; lookups, exact answers, done. So why do we need anything else?&lt;/p&gt;

&lt;p&gt;Memory.&lt;/p&gt;

&lt;p&gt;Say you're tracking 1 billion URLs a web crawler has already visited, so you don't crawl them twice. An average URL is ~70 bytes. Even if you &lt;em&gt;only&lt;/em&gt; stored the raw strings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1,000,000,000 URLs × 70 bytes ≈ 70 GB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's before the overhead of the hash set itself — pointers, load-factor slack, bucket arrays. Realistically you're looking at well north of 100 GB of RAM to answer a yes/no question. You can shard it across machines, sure, but now every "have I seen this?" check is a network hop.&lt;/p&gt;

&lt;p&gt;Here's the reframe that unlocks everything:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You don't actually need to &lt;em&gt;store&lt;/em&gt; the URLs. You only need to &lt;em&gt;recognize&lt;/em&gt; them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A bouncer doesn't keep a photocopy of every ID he's ever checked. He keeps a much smaller mental fingerprint. A Bloom filter is that bouncer.&lt;/p&gt;




&lt;h2&gt;
  
  
  The core idea: stop storing, start fingerprinting
&lt;/h2&gt;

&lt;p&gt;A Bloom filter is two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A &lt;strong&gt;bit array&lt;/strong&gt; of &lt;code&gt;m&lt;/code&gt; bits, all starting at &lt;code&gt;0&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A set of &lt;code&gt;k&lt;/code&gt; independent &lt;strong&gt;hash functions&lt;/strong&gt;, each of which maps any input to a position in that bit array.
That's it. No keys, no values, no stored elements. Just a row of bits and some hash functions.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Two operations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;add(x)&lt;/code&gt;&lt;/strong&gt; — hash &lt;code&gt;x&lt;/code&gt; with all &lt;code&gt;k&lt;/code&gt; functions, get &lt;code&gt;k&lt;/code&gt; positions, set those bits to &lt;code&gt;1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;contains(x)&lt;/code&gt;&lt;/strong&gt; — hash &lt;code&gt;x&lt;/code&gt; with the same &lt;code&gt;k&lt;/code&gt; functions, check those &lt;code&gt;k&lt;/code&gt; positions. If &lt;em&gt;all&lt;/em&gt; of them are &lt;code&gt;1&lt;/code&gt;, return &lt;em&gt;"probably yes."&lt;/em&gt; If &lt;em&gt;any&lt;/em&gt; is &lt;code&gt;0&lt;/code&gt;, return &lt;em&gt;"definitely no."&lt;/em&gt;
Read that last line again, because it's the entire personality of the data structure:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;A &lt;code&gt;0&lt;/code&gt; is proof of absence. A &lt;code&gt;1&lt;/code&gt; is only a hint of presence.&lt;/p&gt;
&lt;/blockquote&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%2Fzto4op4t8ailu2qjkmji.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%2Fzto4op4t8ailu2qjkmji.png" alt="add(x): one element is run through k hash functions, each setting one bit to 1" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A worked example you can follow by hand
&lt;/h2&gt;

&lt;p&gt;Let's use a tiny filter: &lt;code&gt;m = 16&lt;/code&gt; bits, &lt;code&gt;k = 3&lt;/code&gt; hash functions. Empty, it looks 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;index:  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
bits:   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Add &lt;code&gt;"cat"&lt;/code&gt;.&lt;/strong&gt; Our three hashes spit out positions &lt;code&gt;3, 9, 13&lt;/code&gt;. Flip them on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;index:  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
bits:   0  0  0 [1] 0  0  0  0  0 [1] 0  0  0 [1] 0  0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Add &lt;code&gt;"dog"&lt;/code&gt;.&lt;/strong&gt; Hashes give &lt;code&gt;1, 9, 14&lt;/code&gt;. Note &lt;code&gt;9&lt;/code&gt; is already &lt;code&gt;1&lt;/code&gt; — that's fine, it just stays &lt;code&gt;1&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;index:  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
bits:   0 [1] 0 [1] 0  0  0  0  0 [1] 0  0  0 [1][1] 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's query.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;contains("cat")&lt;/code&gt;&lt;/strong&gt; → check positions &lt;code&gt;3, 9, 13&lt;/code&gt; → all &lt;code&gt;1&lt;/code&gt; → &lt;strong&gt;"probably yes."&lt;/strong&gt; Correct, we added it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;contains("fish")&lt;/code&gt;&lt;/strong&gt; → hashes to &lt;code&gt;2, 9, 13&lt;/code&gt; → position &lt;code&gt;2&lt;/code&gt; is &lt;code&gt;0&lt;/code&gt; → &lt;strong&gt;"definitely no."&lt;/strong&gt; Correct — and notice we got a guaranteed-correct answer by checking a single zero bit. That's the cheap, certain half of the filter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;contains("bird")&lt;/code&gt;&lt;/strong&gt; → hashes to &lt;code&gt;1, 13, 14&lt;/code&gt; → position &lt;code&gt;1&lt;/code&gt; is &lt;code&gt;1&lt;/code&gt; (set by &lt;em&gt;dog&lt;/em&gt;), &lt;code&gt;13&lt;/code&gt; is &lt;code&gt;1&lt;/code&gt; (set by &lt;em&gt;cat&lt;/em&gt;), &lt;code&gt;14&lt;/code&gt; is &lt;code&gt;1&lt;/code&gt; (set by &lt;em&gt;dog&lt;/em&gt;) → all three are &lt;code&gt;1&lt;/code&gt; → &lt;strong&gt;"probably yes."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But we never added &lt;code&gt;"bird"&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;That's a &lt;strong&gt;false positive&lt;/strong&gt;. No single element claimed those three bits — they got lit up by &lt;em&gt;different&lt;/em&gt; elements, and &lt;code&gt;"bird"&lt;/code&gt; happened to land on exactly that combination. The filter has no way to tell the difference between "one element set all these" and "three different elements each set one."&lt;/p&gt;

&lt;p&gt;This is the price. And here's the beautiful part: &lt;strong&gt;it only goes one way.&lt;/strong&gt;&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%2F75z8fp7w00fazd8a9bwr.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%2F75z8fp7w00fazd8a9bwr.png" alt="Step-by-step trace: adding cat then dog, then querying bird produces a false positive from shared bits" width="800" height="574"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why you get false positives but &lt;em&gt;never&lt;/em&gt; false negatives
&lt;/h2&gt;

&lt;p&gt;A false negative would mean: you added &lt;code&gt;x&lt;/code&gt;, but &lt;code&gt;contains(x)&lt;/code&gt; says no.&lt;/p&gt;

&lt;p&gt;For that to happen, at least one of &lt;code&gt;x&lt;/code&gt;'s &lt;code&gt;k&lt;/code&gt; bits would have to be &lt;code&gt;0&lt;/code&gt;. But &lt;code&gt;add(x)&lt;/code&gt; &lt;em&gt;set all of them to &lt;code&gt;1&lt;/code&gt;&lt;/em&gt;, and &lt;strong&gt;bits in a Bloom filter never go back to zero&lt;/strong&gt; (we'll revisit that caveat later). So once you've added something, every one of its bits is permanently lit. A query for it can only ever find all &lt;code&gt;1&lt;/code&gt;s.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Added elements always return "yes." Bits never un-set. Therefore: zero false negatives, ever.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This asymmetry is what makes Bloom filters &lt;em&gt;useful&lt;/em&gt; rather than just clever. "Definitely no" is a hard guarantee. "Probably yes" is a hint you can verify with a slower, exact check only when needed. You build systems around that shape: use the filter as a fast gate, and only pay the expensive cost when it says "maybe."&lt;/p&gt;




&lt;h2&gt;
  
  
  The implementation
&lt;/h2&gt;

&lt;p&gt;Here's a clean Python version. The only mildly clever bit is how we get &lt;code&gt;k&lt;/code&gt; hash functions without writing &lt;code&gt;k&lt;/code&gt; of them — more on that right after.&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;import&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BloomFilter&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;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected_items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;false_positive_rate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.01&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="c1"&gt;# Size the filter from how many items you expect and the FP rate you'll tolerate.
&lt;/span&gt;        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;_optimal_size&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;expected_items&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;false_positive_rate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;_optimal_hash_count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected_items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;bytearray&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# m bits, packed into bytes
&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;_set_bit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bits&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;|=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;8&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;_get_bit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bits&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;8&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;_hashes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
        Kirsch-Mitzenmacher trick: derive k hashes from just TWO base hashes.
        g_i(x) = (h1(x) + i * h2(x)) mod m.  Statistically as good as k independent hashes.
        &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
        &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;h1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_bytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hashlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sha256&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;digest&lt;/span&gt;&lt;span class="p"&gt;()[:&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;big&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;h2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_bytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hashlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;md5&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;digest&lt;/span&gt;&lt;span class="p"&gt;()[:&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;big&lt;/span&gt;&lt;span class="sh"&gt;"&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;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="nf"&gt;yield &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&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;index&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;_hashes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;_set_bit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&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;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;_get_bit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&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;index&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;_hashes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

    &lt;span class="nd"&gt;@staticmethod&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;_optimal_size&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;max&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="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;

    &lt;span class="nd"&gt;@staticmethod&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;_optimal_hash_count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;max&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="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Usage:&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;bf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BloomFilter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;expected_items&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1_000_000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;false_positive_rate&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.01&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;bf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[email protected]&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;bf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[email protected]&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# True  (definitely added)
&lt;/span&gt;&lt;span class="n"&gt;bf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[email protected]&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    &lt;span class="c1"&gt;# almost certainly False; ~1% chance of a false "True"
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  That double-hashing trick is worth stealing
&lt;/h3&gt;

&lt;p&gt;Naively, &lt;code&gt;k = 7&lt;/code&gt; hash functions means you need 7 genuinely different, well-distributed hash functions. Annoying. The &lt;strong&gt;Kirsch–Mitzenmacher&lt;/strong&gt; result says you don't: take two good base hashes &lt;code&gt;h1&lt;/code&gt; and &lt;code&gt;h2&lt;/code&gt;, and generate the rest as &lt;code&gt;h1 + i·h2&lt;/code&gt;. The false-positive behavior is indistinguishable from using &lt;code&gt;k&lt;/code&gt; independent hashes, and you compute two hashes instead of seven. Production libraries (like the ones in Cassandra and Guava) do exactly this.&lt;/p&gt;




&lt;h2&gt;
  
  
  The math you actually need (no PhD required)
&lt;/h2&gt;

&lt;p&gt;Four variables run the whole show:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Symbol&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;n&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;number of items you'll insert&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;m&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;number of bits in the array&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;k&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;number of hash functions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;p&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;false-positive probability you're willing to accept&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;You pick &lt;code&gt;n&lt;/code&gt; (how much you'll store) and &lt;code&gt;p&lt;/code&gt; (how often you'll tolerate a wrong "maybe"). The other two fall out:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optimal bit-array size:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;m = -(n × ln p) / (ln 2)²
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Optimal number of hash functions:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;k = (m / n) × ln 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Plug in real numbers. For &lt;strong&gt;1 million items at a 1% false-positive rate&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;m ≈ 9.6 million bits ≈ 1.2 MB&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;k ≈ 7&lt;/code&gt; hash functions
Sit with that. A hash set of those keys would be tens of megabytes minimum. The Bloom filter answers the same membership question in &lt;strong&gt;1.2 MB&lt;/strong&gt;. Want a 0.1% false-positive rate instead? It climbs to ~1.8 MB. Still tiny.&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%2F7qbj3xosshlcvo920bda.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%2F7qbj3xosshlcvo920bda.png" alt="False-positive rate drops exponentially as bits-per-element grows; ~9.6 bits gives 1%, ~14.4 bits gives 0.1%" width="800" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The intuition behind the knobs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Too few hash functions&lt;/strong&gt; → not enough bits set per element → easy collisions don't get distinguished. High FP rate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Too many hash functions&lt;/strong&gt; → the array fills with &lt;code&gt;1&lt;/code&gt;s too fast → everything starts looking present. Also high FP rate.&lt;/li&gt;
&lt;li&gt;There's a &lt;strong&gt;sweet spot&lt;/strong&gt; (that &lt;code&gt;k = (m/n) ln 2&lt;/code&gt; formula), and it lands right around where roughly &lt;strong&gt;half the bits are set&lt;/strong&gt; when the filter is full. That's not a coincidence — a half-full array is the point of maximum information per bit.
And the punchline that makes this practical: &lt;strong&gt;the memory cost per item depends only on &lt;code&gt;p&lt;/code&gt;, not on how big each item is.&lt;/strong&gt; A 70-byte URL and a 10 KB JSON blob cost the &lt;em&gt;same&lt;/em&gt; number of bits in the filter, because you only ever store the hashes. That's why it scales where a hash set can't.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Where this actually runs in production
&lt;/h2&gt;

&lt;p&gt;This isn't a whiteboard toy. It's load-bearing infrastructure in systems you use daily.&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%2F4d8s6yy9xqghkfq7jrae.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%2F4d8s6yy9xqghkfq7jrae.png" alt="The front-gate pattern: a " width="799" height="358"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Databases (Cassandra, HBase, RocksDB, LevelDB, Bigtable).&lt;/strong&gt; These use LSM-tree storage, where data lives in many on-disk files (SSTables). To find a key, you might have to check several files — and disk reads are &lt;em&gt;brutally&lt;/em&gt; slow compared to memory. So each SSTable gets a Bloom filter held in RAM. Before touching disk, the DB asks the filter "could this key be in this file?" A "definitely no" skips the disk read entirely. Given how lopsided the cost is (RAM lookup vs. disk seek), even a filter that's &lt;em&gt;only sometimes&lt;/em&gt; able to say no is a massive win.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Browsers (Chrome's Safe Browsing).&lt;/strong&gt; Chrome warns you before you visit a known-malicious site — without shipping you a list of every dangerous URL on the internet (which would be enormous and instantly stale). A compact local filter answers "is this URL probably bad?" If no → safe, proceed instantly. If maybe → &lt;em&gt;then&lt;/em&gt; it does a real network check. The filter turns "phone home on every single navigation" into "phone home only on the rare maybe."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CDNs and caches.&lt;/strong&gt; "Is this object worth caching?" A common trick: only cache something on its &lt;em&gt;second&lt;/em&gt; request. A Bloom filter cheaply remembers "have I seen this URL once before?" without storing the URLs, filtering out the long tail of one-hit-wonder objects that would just pollute the cache.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Redis&lt;/strong&gt; ships Bloom filters as a module (&lt;code&gt;BF.ADD&lt;/code&gt;, &lt;code&gt;BF.EXISTS&lt;/code&gt;) for exactly this class of problem — dedup, "have I shown this user this item," and so on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Medium&lt;/strong&gt; reportedly used one to track which articles you've already read, so its recommendations don't keep serving you the same posts. A false positive just means it occasionally skips one you hadn't seen — a totally acceptable error for a recommendation feed.&lt;/p&gt;

&lt;p&gt;Notice the pattern in every case: &lt;strong&gt;the filter is a cheap front gate, and the expensive operation (disk, network, recompute) only happens on a "maybe."&lt;/strong&gt; A false positive costs you a wasted check. It never costs you correctness.&lt;/p&gt;




&lt;h2&gt;
  
  
  The catch nobody mentions first: you can't delete
&lt;/h2&gt;

&lt;p&gt;Want to remove an element? You'd flip its &lt;code&gt;k&lt;/code&gt; bits back to &lt;code&gt;0&lt;/code&gt;. Except — those bits might be shared with &lt;em&gt;other&lt;/em&gt; elements you didn't remove. Zero out &lt;code&gt;"cat"&lt;/code&gt;'s bits and you might have just told the filter that &lt;code&gt;"dog"&lt;/code&gt; is gone too, because they overlapped at position &lt;code&gt;9&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Clear those shared bits and you've created the one thing a Bloom filter promised would never happen: a &lt;strong&gt;false negative&lt;/strong&gt;. The whole guarantee collapses.&lt;/p&gt;

&lt;p&gt;So a plain Bloom filter is &lt;strong&gt;add-only&lt;/strong&gt;. If you need deletion, you reach for a variant:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Counting Bloom Filter&lt;/strong&gt; — replace each bit with a small counter (say 4 bits). &lt;code&gt;add&lt;/code&gt; increments, &lt;code&gt;remove&lt;/code&gt; decrements, &lt;code&gt;contains&lt;/code&gt; checks for non-zero. Deletion works, at ~4× the memory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalable Bloom Filter&lt;/strong&gt; — don't know &lt;code&gt;n&lt;/code&gt; in advance? This one chains progressively larger filters as it fills, holding your target FP rate without you having to size it up front.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cuckoo Filter&lt;/strong&gt; — supports deletion &lt;em&gt;and&lt;/em&gt; often uses less space than a counting filter at low FP rates, by storing tiny fingerprints in a cuckoo-hash table. The modern go-to when you need removals.
You don't need these on day one. But knowing they exist means you won't paint yourself into a corner when a requirement changes.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  When to reach for one (and when not to)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Reach for a Bloom filter when:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The expensive thing is a disk read, network call, or recomputation — and you want to skip it on definite misses.&lt;/li&gt;
&lt;li&gt;"Probably yes, let me double-check" is an acceptable answer.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You have way more data than RAM, and exact membership is a luxury you can't afford.&lt;br&gt;
&lt;strong&gt;Skip it when:&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You need the actual stored values back, not just yes/no. (It stores nothing. There's nothing to retrieve.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A false positive is dangerous rather than merely wasteful — e.g. "is this transaction already processed?" where a wrong "yes" means silently dropping a real payment.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  - Your dataset is small enough that a plain hash set fits comfortably. Don't add probabilistic machinery to save a few megabytes you weren't short on.
&lt;/h2&gt;

&lt;h2&gt;
  
  
  The one-line takeaway
&lt;/h2&gt;

&lt;p&gt;A Bloom filter trades a sliver of accuracy — in a single, controllable, never-dangerous direction — for an enormous cut in memory. It can't tell you what's in the set, and it'll occasionally claim something's there when it isn't. But when it says &lt;strong&gt;"definitely not,"&lt;/strong&gt; it is never, ever wrong.&lt;/p&gt;

&lt;p&gt;In a world where the slow part is almost always disk or network, a structure that lets you confidently &lt;em&gt;skip&lt;/em&gt; work is worth far more than one that's perfectly precise. Being wrong on purpose, in exactly the right way, turns out to be one of the most useful tricks in systems engineering.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;If you build one, try logging your actual false-positive rate against the &lt;code&gt;p&lt;/code&gt; you configured — watching the math hold up in practice is oddly satisfying. And if you want to really internalize it: implement &lt;code&gt;contains&lt;/code&gt; first and watch it return &lt;code&gt;True&lt;/code&gt; for things you never added. That moment of "wait, that's a feature?" is when it clicks.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>datastructures</category>
      <category>systemdesign</category>
      <category>programming</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>I Built Cursor for Spreadsheets.. But What for?</title>
      <dc:creator>Hassan Zahar Rifat</dc:creator>
      <pubDate>Tue, 01 Jul 2025 20:30:53 +0000</pubDate>
      <link>https://dev.to/hzahar/i-built-cursor-for-spreadsheets-but-what-for-364e</link>
      <guid>https://dev.to/hzahar/i-built-cursor-for-spreadsheets-but-what-for-364e</guid>
      <description>&lt;h2&gt;
  
  
  🚀 Why I Built It
&lt;/h2&gt;

&lt;p&gt;I manage a side project with a customer base, and like a lot of solo builders, I frequently use Google Sheets to keep track of metrics, revenue, and day-to-day data.&lt;/p&gt;

&lt;p&gt;Over time, I found myself doing the same repetitive tasks — writing formulas, cleaning up tables, copying logic across rows and it started to feel inefficient. Not difficult, just unnecessarily manual.&lt;/p&gt;

&lt;p&gt;That’s when I realized I didn’t want to build another product just for the sake of the hackathon. I wanted to build something that I would actually use, something would solve a real business problem.&lt;/p&gt;

&lt;p&gt;So I scrapped my original idea and started working on a spreadsheet that behaves more like an assistant. One where I could type plain language and get back working formulas, insights, or even full summaries without needing to remember exact syntax or jump between tabs.&lt;/p&gt;

&lt;p&gt;That’s how &lt;strong&gt;Cellmate AI&lt;/strong&gt; started.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔧 Building with Bolt
&lt;/h2&gt;

&lt;p&gt;Once I committed to the idea, I had around 15 days left in the World's Largest Hackathon presented by Bolt. To move quickly, I relied on &lt;a href="https://bolt.new" rel="noopener noreferrer"&gt;Bolt.new&lt;/a&gt; to scaffold most of the application — from UI components to basic functionality.&lt;/p&gt;

&lt;p&gt;Almost every major feature started with a Bolt prompt.&lt;/p&gt;

&lt;p&gt;Some initial examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;"Create a React spreadsheet grid with editable cells"&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;"Add a formula bar which will for now contain the cell value"&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;"Add a toolbar with basic formatting like color, bg, alignments"&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;"Add CSV import/export support"&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bolt helped me move fast, especially when I broke down prompts into focused tasks. Larger prompts often generated bloated or buggy code, so I kept things small and stitched the parts together manually.&lt;/p&gt;

&lt;p&gt;When Bolt-generated output broke existing logic or styling, I cleaned it up myself. I avoided over-engineering and left out anything that wasn't essential.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Prompt Strategy and Workflow
&lt;/h2&gt;

&lt;p&gt;My workflow eventually settled into this loop:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Write a clear, single-purpose prompt&lt;/li&gt;
&lt;li&gt;Let Bolt generate a scaffold&lt;/li&gt;
&lt;li&gt;Test it immediately&lt;/li&gt;
&lt;li&gt;Patch or rewrite the pieces that broke&lt;/li&gt;
&lt;li&gt;Move to the next task&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By keeping each step tight, I avoided the usual AI-overhead and kept things predictable. This approach worked well — especially when combining AI-generated logic with my own cleanup.&lt;/p&gt;




&lt;h2&gt;
  
  
  📸 What the App Does
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Cellmate AI&lt;/strong&gt; is a lightweight spreadsheet app with built-in AI support — designed to make working with data faster and less manual.&lt;/p&gt;

&lt;p&gt;Here’s what it currently supports:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Formula generation from plain text&lt;/strong&gt;&lt;br&gt;
Type something like &lt;code&gt;"Sum column B if column C is complete"&lt;/code&gt; and it returns a working &lt;code&gt;=SUMIF()&lt;/code&gt; formula.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sheet-level changes via prompt&lt;/strong&gt;&lt;br&gt;
You can ask it to delete rows, add columns, or clean up sections without touching any menu.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Natural language insights&lt;/strong&gt;&lt;br&gt;
Ask questions like &lt;code&gt;"Which product had the highest revenue?"&lt;/code&gt; or &lt;code&gt;"How many users signed up last week?"&lt;/code&gt; — and it gives you answers based on the data in the sheet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Auto-generated summary reports&lt;/strong&gt;&lt;br&gt;
One prompt can generate a full summary of the sheet contents.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CSV import/export&lt;/strong&gt;&lt;br&gt;
Quickly upload or download data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Supabase integration for persistence and auth&lt;/strong&gt;&lt;br&gt;
User sessions and sheet data are synced using Supabase — so it works across devices.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧰 Tech Stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Bolt (scaffolding + code generation)&lt;/li&gt;
&lt;li&gt;React + TypeScript
&lt;/li&gt;
&lt;li&gt;ShadCN&lt;/li&gt;
&lt;li&gt;TailwindCSS
&lt;/li&gt;
&lt;li&gt;Vite
&lt;/li&gt;
&lt;li&gt;OpenAI (natural language → formula/insight)
&lt;/li&gt;
&lt;li&gt;Supabase (auth + database)
&lt;/li&gt;
&lt;li&gt;Hosted on Netlify&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ✅ What’s Working
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Spreadsheet grid with editable cells
&lt;/li&gt;
&lt;li&gt;Formula generation from plain text
&lt;/li&gt;
&lt;li&gt;Sheet-level structural changes via prompt
&lt;/li&gt;
&lt;li&gt;Insights and summary report generation
&lt;/li&gt;
&lt;li&gt;CSV import/export
&lt;/li&gt;
&lt;li&gt;User login and data sync via Supabase&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Here's a demo video describing the current stage (0.75x might help):&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/68-IMUzXERc"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;




&lt;h2&gt;
  
  
  🐞 What’s Missing (for now)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;No multi-sheet/tab support
&lt;/li&gt;
&lt;li&gt;No real-time collaboration
&lt;/li&gt;
&lt;li&gt;No AI-generated charting or visualization tools
&lt;/li&gt;
&lt;li&gt;Some UX rough edges in prompt result placement&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  💡 What I Learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Building from a real pain point made it easier to stay focused.&lt;/li&gt;
&lt;li&gt;Bolt can be used beyond prototyping; it landed some great features by providing clear-cut instructions.&lt;/li&gt;
&lt;li&gt;Prompt clarity mattered more than prompt length — vague requests broke things quickly. (Thanks to revert/undo option)&lt;/li&gt;
&lt;li&gt;I didn’t try to do everything, and it helped me finish a foundational MVP.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔜 What’s Next
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Support for Excel file uploads
&lt;/li&gt;
&lt;li&gt;Summary dashboards and report saving
&lt;/li&gt;
&lt;li&gt;Sharing and collaboration features
&lt;/li&gt;
&lt;li&gt;Possibly releasing a public version with pricing&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Thanks to Bolt, DEV, and the hackathon team — the pressure helped me shift gears and build something that I'm happy about.&lt;/p&gt;

&lt;p&gt;Try it out: &lt;a href="https://cellmateai.xyz" rel="noopener noreferrer"&gt;https://cellmateai.xyz&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Questions, feedback, bugs? Happy to hear them.&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>wlhchallenge</category>
      <category>bolt</category>
      <category>ai</category>
    </item>
    <item>
      <title>Communication Among Services in Microservices Architecture? Let's Clear it Out!</title>
      <dc:creator>Hassan Zahar Rifat</dc:creator>
      <pubDate>Mon, 27 May 2024 19:10:37 +0000</pubDate>
      <link>https://dev.to/hzahar/communication-among-services-in-microservices-architecture-lets-clear-it-out-14h6</link>
      <guid>https://dev.to/hzahar/communication-among-services-in-microservices-architecture-lets-clear-it-out-14h6</guid>
      <description>&lt;p&gt;When services communicate with each other in a microservices architecture, there are two common patterns: Sync and Async.&lt;/p&gt;

&lt;p&gt;In Sync architecture, services call each other typically via direct API calls or other request/response methods. This means that if a service is down, all other dependent services are also down. But this pattern can simplify handling data consistency and reduce data duplication as each service can fetch data when needed.&lt;/p&gt;

&lt;p&gt;In Async architecture, services send messages to each other via messaging systems like message queues or event streams where messages are sent without requiring an immediate response. Services are relatively independent and don’t need to wait for each other to respond. If one service fails, other services continue functioning without caring much and will process messages as they become available once the failed service is restored. But this approach usually requires data duplication and extra consistency handling mechanisms, since each service most likely needs to have its own data copy to serve independently.&lt;/p&gt;

&lt;p&gt;It might seem like the async approach is the best choice for unicorn projects, but this isn't always the case. Whether to use Sync or Async pattern depends on various factors such as the requirements of the software, budget, market demand, etc. It's important to note that gaining one advantage usually means sacrificing another. Most large-scale software is built on a hybrid pattern to maximize optimization.&lt;/p&gt;

&lt;p&gt;I'm building a simple application using microservices architecture in my free time for fun.&lt;/p&gt;

&lt;p&gt;Shoot any questions you have. Stay tuned to get updates &amp;lt;3&lt;/p&gt;

</description>
      <category>microservices</category>
      <category>architecture</category>
      <category>softwareengineering</category>
      <category>software</category>
    </item>
    <item>
      <title>10 Impeccable JavaScript Projects for Beginners</title>
      <dc:creator>Hassan Zahar Rifat</dc:creator>
      <pubDate>Mon, 26 Jun 2023 09:17:32 +0000</pubDate>
      <link>https://dev.to/hzahar/10-impeccable-javascript-projects-for-beginners-2b53</link>
      <guid>https://dev.to/hzahar/10-impeccable-javascript-projects-for-beginners-2b53</guid>
      <description>&lt;p&gt;Hey, JavaScript enthusiasts! &lt;/p&gt;

&lt;p&gt;Congrats on your decision of learning JavaScript. You've entered into an ocean of opportunities. Now, here without any biting around the bush, I'd help you to push your level forward from novice to semi-intermediate.&lt;/p&gt;

&lt;p&gt;How's that possible? Well, your skills could be sharpen like a sword only by doing projects. But what projects would be the best fit for beginners? We'll uncover that now.&lt;/p&gt;

&lt;p&gt;If you're just starting out with JavaScript, I could suggest 10 hottest beginner-friendly JS projects:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Drum Kit:
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;Create a virtual drum kit where users can play different drum sounds by pressing corresponding keys on their keyboard or by clicking on the drum pads. Enhance it with visual feedback and interactive animations. &lt;/p&gt;

&lt;p&gt;Play the 'numb', record, and share!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  2. Image Slider:
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;Develop an image slider that cycles through a collection of images. Implement features like navigation arrows, auto-play, and image captions. You can even add transition effects for a visually appealing slider. It'd be a great utility library.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  3. Quiz Application:
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;Develop an interactive quiz app with multiple-choice questions. Implement a scoring system, timers, and a progress bar to make it engaging. Add different difficulty levels or integrate external APIs to fetch quiz questions from various categories.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  4. Expense Tracker:
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;Build an expense tracker that allows users to add and categorize their expenses. Implement features like income tracking, expense filtering, and graphical representations of spending patterns. It'd help you grasp data manipulation and data visualization.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  5. Chat Application:
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;Develop a real-time chat application using technologies like Node.js and Socket.IO. Enable users to join rooms, exchange messages, and display online/offline status. Enhance it further with features like file sharing and user authentication.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  6. Recipe Finder:
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;Create a recipe finder app that fetches recipes from various sources using APIs. Implement search filters, sorting options, and user ratings. You can even include advanced features like dietary restrictions, personalized recommendations, and meal planning.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  7. GitHub Profile Viewer:
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;Develop an application that fetches and displays GitHub user profiles. Include features like repositories, followers, activity feeds, and user statistics. You can also experiment with data visualization libraries to present the information.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  8. Music Player:
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;Build a sleek and user-friendly music player that can stream and play music from various sources. Implement features like playlists, song searching, and audio visualization. Take it a step further by integrating APIs to fetch lyrics or album information.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  9. E-commerce Store:
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;Create a fully functional e-commerce website with features like product listing, search, shopping cart, and secure payment integration. Focus on responsive design and smooth user experience.&lt;/p&gt;

&lt;p&gt;I know it's a challenging and super common project, but worth it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  10. Social Media Dashboard:
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;Develop a social media dashboard that aggregates data from multiple platforms like LinkedIn, Twitter, and Instagram. Implement features like post-scheduling, analytics, and social media integration.&lt;/p&gt;

&lt;p&gt;PS: It's my personal favorite!!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Thanks for checking out this blog.&lt;br&gt;
Now the first thing to do:&lt;br&gt;
Pick up one and start.&lt;br&gt;
Happy coding! 🚀&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>coding</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Can I Show Pie Charts on My Website? - Introducing Recharts</title>
      <dc:creator>Hassan Zahar Rifat</dc:creator>
      <pubDate>Sat, 05 Mar 2022 03:18:03 +0000</pubDate>
      <link>https://dev.to/hzahar/can-i-show-pie-charts-on-my-website-introducing-recharts-55p</link>
      <guid>https://dev.to/hzahar/can-i-show-pie-charts-on-my-website-introducing-recharts-55p</guid>
      <description>&lt;p&gt;&lt;strong&gt;Pre-requisite:&lt;/strong&gt; Basic React.js&lt;/p&gt;

&lt;p&gt;Hello developers! Thanks in advance for your interest. Maybe at this moment, you're thinking about improving UX of your website by visualizing data in form of pie charts or something like that. Because at the end of the day, user impression mostly depends on the UX. So the good news is if you're using React, you can work on data visualization easily with Reacharts package.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Reacharts?&lt;/strong&gt;&lt;br&gt;
Hold on a minute before going to the main attraction. Do we know what Reacharts is? According to the official documentation, Recharts is an npm package for using in React projects built on top of the SVG elements (We can follow SVG styling rules to style) with lightweight dependency of D3 (JavaScript library to visualize data) submodules. It's customizable by changing the props values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installation&lt;/strong&gt;&lt;br&gt;
Okay, now! moving on to the installation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install recharts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Importing Components&lt;/strong&gt;&lt;br&gt;
After installation, we can use the components of Recharts by importing. To make a simple pie chart, we need to import ResponsiveContainer, PieChart, Pie, ToolTip. ResponsiveContainer is a wrapping container with responsive behavior. PieChart is a canvas component. Inside this component, one or many Pie component can be declared. Also, Other features of the pie chart(s) of the canvas can be declared inside PieChart (such as: ToolTip). Pie is the component for printing a pie chart. Tooltip is used if we want to show details on hovering.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { ResponsiveContainer, PieChart, Pie, Tooltip } from 'recharts';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Structure of the raw data&lt;/strong&gt;&lt;br&gt;
Let's understand the structure of the data we have to have. In this particular example, we should have an array of objects and each object will have name and value keys with their corresponding values. name (string type) would contain the title of the data and value (number type) would be the data. For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const data = [
  { name: 'A', value: 400 },
  { name: 'B', value: 300 },
  { name: 'C', value: 300 },
  { name: 'D', value: 200 },
  { name: 'E', value: 100 },
  { name: 'F', value: 700 },
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Core Components and Explanation&lt;/strong&gt;&lt;br&gt;
After that, we'll be able to print our pie chart at the twinkles of an eye. We have to write our codes inside return of the component. Let's have a look of the code. Don't worry, I won't leave without explaining necessary parts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    return (
      &amp;lt;ResponsiveContainer width="100%" height="100%"&amp;gt;
        &amp;lt;PieChart width={400} height={400}&amp;gt;
          &amp;lt;Pie
            dataKey="value"
            isAnimationActive={true}
            data={data}
            cx="50%"
            cy="50%"
            innerRadius={0}
            outerRadius={80}
            fill="#8884d8"
            label
          /&amp;gt;
          &amp;lt;Tooltip /&amp;gt;
        &amp;lt;/PieChart&amp;gt;
      &amp;lt;/ResponsiveContainer&amp;gt;
    )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have assigned the canvas size 400x400 in PieChart component. After that, we have decent amount of props in Pie components in form of SVG styling. cx and cy defines the position of x and y axis respectively. Assigning 50% both in cx and cy means the pie chart will be shown at the center. label means label={true} and we'll get the pie chart labeled with the values nicely if label is true. isAnimationTrue sets default animations. If we don't want the animation, we have to assign false. fill would be used to set background color. outerRadius defines the solid redial size. But if we want to make the pie hollow, we need to change the value of innerRadius and assign more than 0. Most importantly, We need to pass the dataset as props named data. And finally, we must have to define the dataKey prop with value, so that it can extract the value of the value key of the dataset and do the elementary math for visualizing the pie chart.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Concluding Remarks&lt;/strong&gt;&lt;br&gt;
So far, we've got enough for getting started. If you like and appreciate this blog, we'll be going deeper towards data visualization. &lt;em&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;/em&gt; &lt;em&gt;I'm not gonna attach any preview image of pie chart. Try it yourself, show us the pies and Best of luck!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>recharts</category>
      <category>react</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Wanna Create your Own Version of Messenger? - Learn Setting up Socket.io</title>
      <dc:creator>Hassan Zahar Rifat</dc:creator>
      <pubDate>Fri, 25 Feb 2022 14:04:30 +0000</pubDate>
      <link>https://dev.to/hzahar/wanna-create-your-own-version-of-messenger-learn-setting-up-socketio-3lkj</link>
      <guid>https://dev.to/hzahar/wanna-create-your-own-version-of-messenger-learn-setting-up-socketio-3lkj</guid>
      <description>&lt;p&gt;&lt;strong&gt;Pre-requisite:&lt;/strong&gt; Basic React.js, Basic Express.js, CLI&lt;/p&gt;

&lt;p&gt;Hello amazing developers! Feeling bored? How about starting to make something like Messenger, Whatsapp or text version of Zoom? You know something very basic about React, Express and you're good to go.&lt;/p&gt;

&lt;p&gt;Today, we'll start learning Socket.io to serve our goal and at the end of this writing, we'll be able to setup Socket.io perfectly. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Socket.io?&lt;/strong&gt;&lt;br&gt;
-&amp;gt; According to the official documentation, Socket.io is a library that enables real-time, bidirectional, event-based communication between browser (client side) and server.&lt;/p&gt;

&lt;p&gt;It uses WebSocket connection (computer communications protocol providing full duplex channel over a TCP connection) whenever possible and if not, it takes HTTP long polling technology (Half duplex connection). WebSocket [a whole another chapter] connection is pretty fast as users can spontaneously send and receive data through this connection.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;One important note:&lt;/em&gt; Socket.io is easier to use and gives more features than that of WebSocket and also it definitely uses WebSocket for data transportation, but it cannot send data from its client side to WebSocket server and vice-versa. Okay, enough of theoretical jargons. Let's make real good stuff now! &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installation:&lt;/strong&gt; We have to install socket.io, express, cors, nodemon (to run the server continuously) in node server. Also we need to initialize the server to configure the package.json file and create an index.js file in where we will write the code. Then We'll install react and socket.io-client for client side. Finally, we'll run both the server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Server side:&lt;/strong&gt; In package.json, inside "scripts": {...}, add&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"start": "node index",
"start-dev": "nodemon index"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
echo null &amp;gt; index.js [using CMD]
npm install -g nodemon
npm install socket.io express cors
npm run start-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Client side:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app name-of-the-app
cd name-of-the-app
npm install socket.io-client
npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now what? - Now, first set up the server with some complementary works. we'll import express, cors (!important), the socket.io package. built in http node module (this will be used to create an http server). After that, we'll have to specify the port number with proccess.env.PORT || 5000. (proccess.env.PORT will be used after deployment by the hosting sites).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const cors = require('cors');
const socketio = require('socket.io');
const http = require('http');
const port = proccess.env.PORT || 5000;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we'll initialize express and use cors (Cross-Origin Rrsource Sharing &amp;gt;&amp;gt; helps to prevent blocking requests due to different origin. For example, request from localhost:3000 to localhost:5000 will be blocked if we don't use cors ).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const app = express();
app.use(cors());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we'll create an http server on top of express and connect it with socket.io.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const server = http.createServer(app);
const io = socketio(server, {options});
// , {options} won't be written for now;
// will be used in future to handle cors policy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, inside the io.on() method 'connection' event will be declared with an instant of socket.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;io.on('connection', (socket) =&amp;gt; {
    // console.log('New connection!');
    // codes...
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All the codes related to socket.io will written inside this method. Now, moving on to the client side. To set all up, we'll import socket.io-client and pass the endpoint containing server side url inside the useEffect without any dependency so that it remain connected.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import io from 'socket.io-client';
...
...
// Inside Component
let socket;
useEffect(() =&amp;gt; {
    socket = io('http://localhost:5000/')
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, thus installation, client-server side initialization and basic setup can easily be handled.&lt;/p&gt;

&lt;p&gt;If you like this blog, we'll definitely be going deeper towards Socket.io in my upcoming blogs. Happy developing :3 &lt;/p&gt;

</description>
      <category>socketio</category>
      <category>express</category>
      <category>react</category>
      <category>beginners</category>
    </item>
    <item>
      <title>You Must Know the Answers to the 7 Most Basic Questions about React</title>
      <dc:creator>Hassan Zahar Rifat</dc:creator>
      <pubDate>Wed, 12 Jan 2022 17:45:12 +0000</pubDate>
      <link>https://dev.to/hzahar/you-must-know-the-answers-to-the-7-most-basic-questions-about-react-24j2</link>
      <guid>https://dev.to/hzahar/you-must-know-the-answers-to-the-7-most-basic-questions-about-react-24j2</guid>
      <description>&lt;p&gt;&lt;strong&gt;1. What is reactjs? Tell us about advantages and disadvantages of using react js.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;-&amp;gt; React.js is a JavaScript library that is used to build scalable Frontend UI.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Advantages:&lt;/em&gt;&lt;br&gt;
Easy to learn.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Gives syntactic sugar by which HTML code can be written inside JavaScript.&lt;br&gt;
By writing one component once, it can be used whenever it needs to be used.&lt;br&gt;
Huge community support&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Disadvantages:&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Core React.js frameworks is not SEO friendly&lt;br&gt;
Huge dependency on many third party libraries.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;2. What is JSX? How does it work?&lt;/strong&gt;&lt;br&gt;
-&amp;gt; JSX refers to JavaScript XML. It gives syntactic sugar and ease to React.js. By using JSX, we can write HTML code inside JavaScript without the burden of using createElement(), appendChild() or template literals.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. What is Virtual dom? What are the differences between virtual and real dom?&lt;/strong&gt;&lt;br&gt;
Or what is the diff algorithm? How does it work?&lt;br&gt;
-&amp;gt; Virtual DOM is a virtual copy of real DOM. It is kept in memory and is synced with real DOM by ReactDOM. DOM manipulation is a less speedy and less efficient process and this is why without rendering the whole document for a little change changing the particular portion is efficient. Virtual DOM does this very well. Whenever change happens, virtual DOM captures the change using diff algorithm and then it updates just that important part that needs to be updated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Differences between props and state?&lt;/strong&gt;&lt;br&gt;
-&amp;gt; Props are immutable and can be passed as child components but states are mutable, owned by the component and mutable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. What is the purpose of useState? When and why will you use it?&lt;/strong&gt;&lt;br&gt;
-&amp;gt; The useState hook is used for initializing, storing and managing the states of any variable. -&amp;gt; const [state, setState] = useState();&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. What is prop drilling?&lt;/strong&gt;&lt;br&gt;
-&amp;gt; Sometimes it becomes necessary to pass a value to a child component and from that child component to it’s child component as props. This process of nested passing is called prop drilling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. why do we need to inject dependency for useEffect?&lt;/strong&gt;&lt;br&gt;
-&amp;gt; Using useEffect, it’s necessary to inject dependencies as whenever the state of the dependencies change, the code inside the useEffect executes.&lt;/p&gt;

</description>
      <category>react</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
