<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Devworlds on Medium]]></title>
        <description><![CDATA[Stories by Devworlds on Medium]]></description>
        <link>https://medium.com/@devworlds?source=rss-fc71325f0bf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Gpn770FgDxdQhut_zOwWag.jpeg</url>
            <title>Stories by Devworlds on Medium</title>
            <link>https://medium.com/@devworlds?source=rss-fc71325f0bf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 09:40:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@devworlds/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How Redis and Bloomfilter Drastically Reduced Database Queries in My Go Project]]></title>
            <link>https://devworlds.medium.com/how-redis-and-bloomfilter-drastically-reduced-database-queries-in-my-go-project-31ccce05908c?source=rss-fc71325f0bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/31ccce05908c</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[bloom-filter]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Devworlds]]></dc:creator>
            <pubDate>Mon, 02 Sep 2024 03:29:19 GMT</pubDate>
            <atom:updated>2024-09-02T03:36:00.966Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*IjHbRXPihIPHemYRrHX9BQ.png" /><figcaption>Gopher Time</figcaption></figure><h3>Introduction</h3><p>The application listens to events generated by the blockchain and checks if the wallets registered in the database are mentioned in any of these Transfer events. Initially, the project would perform a database query for each event received, which would quickly become a bottleneck, compromising the system’s performance.</p><p>To solve this problem, I explored ways to reduce the database queries while maintaining the integrity of the checks. It was then that by using Redis and Bloom Filter, technologies that together allowed for a significant reduction in the number of necessary queries, drastically improving the application’s performance.</p><h3>The Project on GitHub</h3><p>The example project i developed is available on GitHub and aims to monitor specific events in Ethereum contracts, checking if any wallet registered in the database is involved in these events. When a wallet is mentioned, the system logs the corresponding event.</p><p><a href="https://github.com/devworlds/eventlistener-redis-bloomfilter">Link to the project on GitHub</a></p><p>The motivation behind this project was the need for a fast and efficient system that could handle a large number of events without overloading the database.</p><h3>Challenges with Frequent Database Queries</h3><p>At the beginning, each processed event resulted in a database query to check if the associated wallet was registered. In an environment with a high volume of transactions, this would quickly become unsustainable. The increase in response time and excessive consumption of database resources were evident.</p><h3>Introducing Redis and Bloom Filter</h3><p><strong>Redis</strong>: Redis is an in-memory data structure store, which can be used as a database, cache, or message broker. Its speed and flexibility make it ideal for storing information that needs to be accessed quickly.</p><p><strong>Bloom Filter</strong>: The Bloom Filter is a probabilistic data structure that allows you to check for the presence of an element in a set efficiently, albeit with the possibility of false positives. This structure is particularly useful when you want to avoid redundant database queries.</p><h3>Implementation in the Project</h3><p>The implementation started with the configuration of Redis as a cache, where Redis is responsible for saving the Bloom Filter in cache. Whenever a new wallet is added to the database, it is also added to the Bloom Filter. Redis then publishes a message indicating that a new wallet has been added and the current Bloom Filter is outdated. The API, upon hearing the published message, updates the Bloom Filter from the cache and restarts the application with the updated data. Whenever an event is received, the application first checks if the wallet is present in the Bloom Filter. If it is, the database is consulted to verify if the wallet really exists, as a secondary verification. If it is not present, no database call is made.</p><h3>Results: Reduction in Database Queries</h3><p>After implementing this approach, I observed a drastic reduction in database queries. With most checks being handled by the Bloom Filter, the number of database queries was reduced by over 80%.</p><p>Furthermore, the application’s response time improved significantly, making the system more scalable and efficient.</p><h3>Final Considerations</h3><p>This project taught me a lot about the importance of choosing the right tools to optimize an application’s performance. The combination of Redis and Bloom Filter proved to be extremely effective in reducing the database load and improving scalability.</p><p>In the future, I plan to explore other optimizations, such as adjusting the Bloom Filter parameters for different use cases and introducing other caching techniques.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31ccce05908c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>