<?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: Kartikey Srivastava</title>
    <description>The latest articles on DEV Community by Kartikey Srivastava (@kartikey_srivastava).</description>
    <link>https://dev.to/kartikey_srivastava</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%2F2201420%2F219c7342-d1ef-448c-bab4-81f0d3b21a17.jpeg</url>
      <title>DEV Community: Kartikey Srivastava</title>
      <link>https://dev.to/kartikey_srivastava</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kartikey_srivastava"/>
    <language>en</language>
    <item>
      <title>Optimizing an API Response</title>
      <dc:creator>Kartikey Srivastava</dc:creator>
      <pubDate>Thu, 17 Oct 2024 03:30:00 +0000</pubDate>
      <link>https://dev.to/kartikey_srivastava/optimizing-an-api-response-lm9</link>
      <guid>https://dev.to/kartikey_srivastava/optimizing-an-api-response-lm9</guid>
      <description>&lt;p&gt;As backend engineers, we frequently deal with API latency issues. It’s easy to create an endpoint and invoke a method when the endpoint is hit, but the real question is: Is that API efficient?&lt;/p&gt;

&lt;p&gt;What is the response time? If it’s not a background task, anything over 1500 ms can feel excessive. Now, imagine you’re on a platform’s checkout page, ready to make a payment. You click “Pay,” and a message appears: “Do not refresh or press the back button.” But the screen gets stuck. Your money has been debited, yet you still don’t see a successful transaction. How frustrating would that be?&lt;/p&gt;

&lt;p&gt;These situations often make the end users feel like switching to some other platform and use their services. The business can get affected and what not.&lt;/p&gt;

&lt;p&gt;While keeping that scenario in mind, let’s shift our focus to the solution. It’s time to optimize our APIs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep Payload size in check:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ever tried uploading an image to some platform and it says, the image should be within “x” kb/mb?&lt;/li&gt;
&lt;li&gt;Performance largely depends on how quickly the server is able to process the request.&lt;/li&gt;
&lt;li&gt;As you increase the payload size, it becomes more and more complex for the server to process the same and it might compromise on the latency while giving the response.&lt;/li&gt;
&lt;li&gt;Applications dealing with large image files often define limits to prevent the end users from uploading images beyond a certain size.&lt;/li&gt;
&lt;li&gt;This helps server to function smoothly.&lt;/li&gt;
&lt;li&gt;So, the next time a site asks you to reduce image size, don’t complain,,, just remember it’s for better performance! :)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Compress your API response:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Let’s understand this with an example of Git ZIP file analogy.&lt;/li&gt;
&lt;li&gt;When we talk about compressing api responses, think of it like downloading a Git respository as a ZIP file.&lt;/li&gt;
&lt;li&gt;Here’s how: Imagine you are cloning a git repository. You have 2 options:&lt;/li&gt;
&lt;li&gt;Clone the entire repo with Git which pulls entire file and history as it is.&lt;/li&gt;
&lt;li&gt;Download it as a ZIP file that compresses the file into a smaller package making the download faster.&lt;/li&gt;
&lt;li&gt;In the same way, when your browser requests data from a server, instead of sending that huge data(like cloning an entire repo), it can compress the data/response (similar to zip file).&lt;/li&gt;
&lt;li&gt;This makes it faster to transfer the data across the internet.&lt;/li&gt;
&lt;li&gt;The only difference that lies here is that you manually extract the files whereas the browser does it automatically.&lt;/li&gt;
&lt;li&gt;The idea is to compress the size of the data to make the process more efficient.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Pagination:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Imagine you are trying to buy a smartphone from Amazon in it’s Great Indian festival sale.&lt;/li&gt;
&lt;li&gt;If for a smartphone search request, Amazon loads all the smartphone at once on a single page it would lead to slower page load or it might even crash.&lt;/li&gt;
&lt;li&gt;To prevent this failure, you see somewhere around 20–30 smartphones per page and in the end you see a “Next” page button.&lt;/li&gt;
&lt;li&gt;This helps in smooth functioning of the backend servers as with less data(30 items) to handle, it can send back the response faster improving overall speed.&lt;/li&gt;
&lt;li&gt;Pagination basically means breaking down a large data set into smaller chunks that are easy to manage.&lt;/li&gt;
&lt;li&gt;Instead of showing all the data at once, you only display a small chunk of it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Remove unnecessary processing on the server:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is one of the most avoided mistakes developers do in daily life.&lt;/li&gt;
&lt;li&gt;It might be overuse of printing logs in the console after every line or it might be making db calls every now and then.&lt;/li&gt;
&lt;li&gt;If there is some frequently accessed data, or maybe some calculation done on the same data repeatedly for different users, the application can cache the result and avoid hitting the db.&lt;/li&gt;
&lt;li&gt;This can result in significant load reduction on the db as well as it will help the server to retrieve results more quickly, improving overall performance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Optimizing API responses is crucial for creating a good user experience. By keeping the above points in check, one can enhance his/her API’s performance.&lt;/p&gt;

&lt;p&gt;Can you think of some other methods that might help us in improving our backend more in terms of api latency?&lt;/p&gt;

&lt;p&gt;If you liked this post, do consider liking and you can also share and follow for more such content :).&lt;/p&gt;

</description>
      <category>api</category>
      <category>backenddevelopment</category>
      <category>backend</category>
      <category>performance</category>
    </item>
    <item>
      <title>How to choose the right database?</title>
      <dc:creator>Kartikey Srivastava</dc:creator>
      <pubDate>Wed, 16 Oct 2024 03:30:00 +0000</pubDate>
      <link>https://dev.to/kartikey_srivastava/how-to-choose-the-right-database-300d</link>
      <guid>https://dev.to/kartikey_srivastava/how-to-choose-the-right-database-300d</guid>
      <description>&lt;p&gt;Being a software developer isn’t just about making a system and getting it running. Imagine you’ve developed an application without knowing how big its user base could grow. You tried to make its performance exceed expectations by using an in-memory database like Redis. You are very happy with the response and money you’re making because of your hard work. Now imagine the user base starts to explode and your current database setup isn’t ready for that. You don’t want to lose your current users but you’re not even able to handle them. Yes I am talking about a social media giant named Instagram.&lt;/p&gt;

&lt;p&gt;Instagram in its initial stage used Redis as its database. Redis is a fast in-memory key-value store. It worked really well when the Instagram’s user base was small. But as the Instagram’s popularity exploded, it saw limitations. We like, comment, post media on Instagram every second. That basically means we are talking of not less than a million writes on the database per second. It wasn’t easy to manage this volume of writes using Redis which is a pure in-memory database(meaning your data handling would always be limited according to your RAM).&lt;/p&gt;

&lt;p&gt;Eventually, Instagram made a significant switch to Cassandra, a distributed NoSql database. End of story.&lt;/p&gt;

&lt;p&gt;I want you to understand how important it is to choose the right tools in your software development journey. Ignoring it today will make you suffer tomorrow.&lt;/p&gt;

&lt;p&gt;Before we move on to “why this, why not that?”, let me walk you through the introduction of “this” and “that”.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Relational Database:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;We all know these databases organize data in table format where each table is a collection of rows and each row is a collection of columns. These databases in their early stages were used to track sales or process bank transactions. A developer interacted with the data through SQL. To give you an example, PostgreSQL is one of the most widely used relational database.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NoSQL:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A twitter hashtag that was supposed to be catchy ended up giving name to another type of database. This system gained a lot of popularity because of various reasons some of which were:&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Scales better than relational databases.&lt;/li&gt;
&lt;li&gt;Higher write throughput&lt;/li&gt;
&lt;li&gt;Queries on unstructured data was relatively easier as compared to relational database.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Different systems have different needs, and no single database can cover them all. Some need high availability(just like Instagram) whereas some need high consistency(just like Banks). As a result, organizations today use multiple databases that include both relational and non-relational databases. This approach is termed as Polyglot Persistence.&lt;/p&gt;

&lt;p&gt;Next time you listen a system using multiple DBs, consider it a polyglot persistent system.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9i3r6jsts6bfyf0ce9tv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9i3r6jsts6bfyf0ce9tv.png" alt="Image description" width="502" height="483"&gt;&lt;/a&gt;&lt;br&gt;
The above picture resembles a resume structure. As you can see in order to store the profile of the person mentioned we have multiple tables. Lets say you want to fetch the “end_year” of the above person’s education.&lt;/p&gt;

&lt;p&gt;Your query would somewhat look like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;SELECT e.end_year FROM education_table e JOIN user_table u ON e.user_id = u.user_id;&lt;/code&gt;&lt;br&gt;
Now imagine, if there were more tables inside this and you had to fetch something very granular you would have ended up writing an essay of joins.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;{&lt;br&gt;
  "user_id": 251,&lt;br&gt;
  "first_name": "Bill",&lt;br&gt;
  "last_name": "Gates",&lt;br&gt;
  "summary": "Co-chair of the Bill &amp;amp; Melinda Gates... Active blogger.",&lt;br&gt;
  "region_id": "us:91",&lt;br&gt;
  "industry_id": 131,&lt;br&gt;
  "photo_url": "/p/7/000/253/05b/308dd6e.jpg",&lt;br&gt;
  "positions": [&lt;br&gt;
    {&lt;br&gt;
      "job_title": "Co-chair",&lt;br&gt;
      "organization": "Bill &amp;amp; Melinda Gates Foundation"&lt;br&gt;
    },&lt;br&gt;
    {&lt;br&gt;
      "job_title": "Co-founder, Chairman",&lt;br&gt;
      "organization": "Microsoft"&lt;br&gt;
    }&lt;br&gt;
  ],&lt;br&gt;
  "education": [&lt;br&gt;
    {&lt;br&gt;
      "school_name": "Harvard University",&lt;br&gt;
      "start": 1973,&lt;br&gt;
      "end": 1975&lt;br&gt;
    },&lt;br&gt;
    {&lt;br&gt;
      "school_name": "Lakeside School, Seattle",&lt;br&gt;
      "start": null,&lt;br&gt;
      "end": null&lt;br&gt;
    }&lt;br&gt;
  ],&lt;br&gt;
  "contact_info": {&lt;br&gt;
    "blog": "[http://thegatesnotes.com](http://thegatesnotes.com/)",&lt;br&gt;
    "twitter": "http://twitter.com/BillGates"&lt;br&gt;
  }&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
Above is a json representation of the same resume. Now, if you want to fetch the end year from the education your input would look something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;db.collection_name.find( { "user_id": 251 }, { "education.end": 1, "_id": 0 } )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above NoSQL query has been taken from chat-gpt as I haven’t worked quite a lot on NoSQL.&lt;/p&gt;

&lt;p&gt;If we consider the above case, we can see that the JSON representation has better readability than the traditional schema. If you want to fetch a profile in the realtional example, you need to perform multiple queries or do a “JOIN” dance between the user table and its subordinate tables.&lt;/p&gt;

&lt;p&gt;Below is the json representation of the above One-to-Many relation(user and his data).&lt;/p&gt;

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

&lt;p&gt;There are a lot of reasons of using one database over other but there is no way one can say NoSQL is always better or SQL always sucks. It totally depends on the use cases of both of them and hence most organizations use them together.&lt;/p&gt;

&lt;p&gt;That’s it from my side. If you want to read more about it I’d recommend you a book : Designing Data Intensive Applications by Martin Kleppmann . It’s a gem of a book.&lt;/p&gt;

&lt;p&gt;If you liked this post, please consider liking it and you can also share and follow me for more such content :).&lt;/p&gt;

</description>
      <category>database</category>
      <category>postgres</category>
      <category>mysql</category>
      <category>nosql</category>
    </item>
    <item>
      <title>Caching — An overview</title>
      <dc:creator>Kartikey Srivastava</dc:creator>
      <pubDate>Tue, 15 Oct 2024 03:30:00 +0000</pubDate>
      <link>https://dev.to/kartikey_srivastava/caching-an-overview-36o7</link>
      <guid>https://dev.to/kartikey_srivastava/caching-an-overview-36o7</guid>
      <description>&lt;p&gt;In simple terms, caching means storing the frequently accessed data in a storage where one can quickly retrieve it without the querying the source of truth i.e. the database. This storage is generally a temporary storage. Caching helps in improving the performance of an application by loading the data somewhere near to the application so the time taken in querying the db is reduced and also the number of times a data source is accessed is also reduced.&lt;/p&gt;

&lt;p&gt;Applications can respond to the user requests more quickly improving the overall user experience. It also helps in reducing the load on the database since the data is now being accessed from the cache and not the db. One thing to note here is, Caching is suitable for frequently accessed data.&lt;/p&gt;

&lt;p&gt;We all know CDN servers, DNS servers, Redis cache and Apache Ignite are some of the most commonly used cache in today’s world. I have already talked about CDN and DNS in my previous posts in case you want to read.&lt;/p&gt;

&lt;p&gt;Let’s get an overview again:&lt;/p&gt;

&lt;p&gt;CDN(Content Delivery Network) caches the static content and serves them to the users located in the nearby region.&lt;/p&gt;

&lt;p&gt;DNS(Domain Name System) can cache the IPs of the servers and avoid the long path from the client’s IP to the authoritative server.&lt;/p&gt;

&lt;p&gt;Redis and Apache Ignite are the caches mostly used as databases. Redis follows a Master-slave architecture whereas Ignite follows a distributed data structure.&lt;/p&gt;

&lt;p&gt;There are many types of caching some of which are:&lt;/p&gt;

&lt;p&gt;Client caching&lt;br&gt;
Distributed caching&lt;br&gt;
Database caching&lt;br&gt;
Application caching&lt;/p&gt;

&lt;p&gt;Let’s understand them one by one with the help of examples:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DISTRIBUTED CACHING&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A type of caching that involves storing data across multiple servers/nodes in a network.&lt;/li&gt;
&lt;li&gt;A perfect example for this is Apache Ignite.&lt;/li&gt;
&lt;li&gt;It has 2 caching modes: PARTITIONED and REPLICATION.&lt;/li&gt;
&lt;li&gt;In case of partitioned mode, the data is stored in chunks across multiple servers so if you have 100 units of data and 3 servers…30:30:40 can be the ratio of their storage.&lt;/li&gt;
&lt;li&gt;In case of replication mode, the data is stores as a whole across all the servers so if you have 100 units of data and 3 servers… each one of them would store all 100 units.&lt;/li&gt;
&lt;li&gt;This type of caching is useful when the application requires high availability and scalability. You can always add more nodes in order to scale and also in case a node goes down, the remaining nodes can handle the user requests.&lt;/li&gt;
&lt;li&gt;However, distributed caching trades of consistency in order to achieve high availability.&lt;/li&gt;
&lt;li&gt;Read about CAP Theorem and you’ll get a better clarity of why distributed caching follows an eventual consistency pattern.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;DATABASE CACHING&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Database caching involves storing frequently accessed data in-memory rather than fetching it from the primary database every time, which reduces database load and improves overall performance.&lt;/li&gt;
&lt;li&gt;By routing the requests to the cache, you can achieve a much lower latency and also reduce the load on the database which includes querying it every time a request comes in.&lt;/li&gt;
&lt;li&gt;Instead of querying the database for every request, your application can first check the cache. If the data is found(cache hit), the request is served from the cache. If not found(cache miss), the request is sent to the database. Now this request can be stored in cache for future queries.&lt;/li&gt;
&lt;li&gt;For example, a user requests his/her information for the first time on a server. This request is served directly from the database. With caching, now the requested data is stored closer to the client after the first request, now for every similar request it would be served from the cache instead of your primary db.&lt;/li&gt;
&lt;li&gt;Caching solutions like Redis comes into play here.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;CLIENT CACHING&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;This type of caching involves storing data directly on the client device be it a web browser or a mobile phone.&lt;/li&gt;
&lt;li&gt;It becomes useful for applications that frequently access client’s locally stored information.&lt;/li&gt;
&lt;li&gt;Obviously, the application’s performance improves since now the number of requests to the server has been reduced that also leads to less data being travelled over the network.&lt;/li&gt;
&lt;li&gt;A perfect example for the same is Password storage in Mobile applications. Applications that ask you to enter a password to log into them, they might offer you to save the password on your device with a message like: “Don’t worry, this will be saved locally on your device.”&lt;/li&gt;
&lt;li&gt;Once you give your consent, the password gets stored locally on your device in some encrypted format and the next time you log in, the password field gets automatically populated.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;APPLICATION CACHING&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Here the caching is done within the scope of application.&lt;/li&gt;
&lt;li&gt;API responses, User serssions can be cached and served to the user requests.&lt;/li&gt;
&lt;li&gt;Do not confuse it with database caching. They tend to be similar but are different when it comes to what is being cached.&lt;/li&gt;
&lt;li&gt;Application caching can cache api responses whereas database caching can cache query results.&lt;/li&gt;
&lt;li&gt;Anything at the application level can be cached using application caching be it an api response, a token or some computed value.&lt;/li&gt;
&lt;li&gt;Application cache lies closer to the application whereas database cache lies closer to the database.&lt;/li&gt;
&lt;li&gt;For example, let’s say you have an e-commerce platform. When a user logs in, his/her user session can be stored in the application’s in memory cache and now this session dadta can be served quickly without the need to go to the database.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These are some of the caching techniques. I have kept this post short and brief as I wasn’t feeling quite well but had to keep the streak of posting on weekends alive. Will come with better and detailed posts in future.&lt;/p&gt;

&lt;p&gt;If you liked this post do consider liking it and you can also share and follow me for more such content :).&lt;/p&gt;

</description>
      <category>caching</category>
      <category>redis</category>
      <category>apacheignite</category>
      <category>performance</category>
    </item>
    <item>
      <title>Bloom Filters</title>
      <dc:creator>Kartikey Srivastava</dc:creator>
      <pubDate>Mon, 14 Oct 2024 03:30:00 +0000</pubDate>
      <link>https://dev.to/kartikey_srivastava/bloom-filters-5336</link>
      <guid>https://dev.to/kartikey_srivastava/bloom-filters-5336</guid>
      <description>&lt;p&gt;Imagine walking into a mobile shop that only sells Samsung and OnePlus phones. You ask the shopkeeper for an iphone. Without wasting any time, he says, “No, we don’t sell iphones.” Now, you change your mind to buy a One Plus model(a rare one). Instead of denying straightaway, the shopkeeper responds, “It might be in stock, but I can’t be 100% sure until I look.”&lt;/p&gt;

&lt;p&gt;This is similar to how a Bloom Filter works, it can definitely tell you if something doesn’t exist(like an iphone in an android shop), but if it says something might exist, there is a certain uncertainty of the data’s presence.&lt;/p&gt;

&lt;p&gt;To keep it more simple, Bloom Filter can give you a false positive(i.e. return true for something that is false). But it can never give you a false negative(i.e. return false for something that is true).&lt;/p&gt;

&lt;p&gt;We all have encountered those warning messages while signing up on some platform that says, “Username already taken/exists”. That’s Bloom Filters in picture(not always as there are some more methods like querying the database or cache but that becomes inefficient when the user traffic explodes).&lt;/p&gt;

&lt;p&gt;Let’s understand this Data Structure bit by bit:&lt;/p&gt;

&lt;p&gt;A Bloom Filter is a probabilistic data structure. Now what does that mean?&lt;/p&gt;

&lt;p&gt;Probabilistic in context of data structures means that this data structure provides answers with a certain possibility of being correct. This filter can definitely say when an element is not present inside it, but it might be wrong in some cases when it says, “Yes, I have this data”.&lt;/p&gt;

&lt;p&gt;A bloom filter uses a bit array to store the data. Now when I say it stores the data, it doesn’t store the actual raw data but applies some hash functions to those data sets and accordingly marks the corresponding positions in the bit array. For example, if you want to check if “Kartik” exists inside a bloom filter it will apply multiple hash functions to this input and then mark their corresponding indexes as 1.&lt;/p&gt;

&lt;p&gt;Let’s break this down:&lt;/p&gt;

&lt;p&gt;Input — ‘Kartik’ to be added inside a bloom filter.&lt;br&gt;
Hash functions applied: Since a bloom filter uses multiple hash functions, we will consider it has 3 for better understanding.&lt;br&gt;
Positions to be marked: Since this filter uses a bit array(a relatively large size bit arrray) where all indexes are set to 0(switch off) by default, based on the hash function’s result the positions will be marked as 1(switch on).&lt;br&gt;
That’s it. The data is stored now. Go ahead to check if it is present or not.&lt;br&gt;
Below is a visual representation of hash functions being applied to an input:&lt;/p&gt;

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

&lt;p&gt;Now, the outputs of the above hash functions(3, 5, 9) are the positions that need to be set. Below is its visual representation:&lt;/p&gt;

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

&lt;p&gt;As you can see the positions 3,5 and 9 are set to 1.&lt;/p&gt;

&lt;p&gt;Checking if the data is present in the filter or not:&lt;/p&gt;

&lt;p&gt;You give the input. Let’s say the input is again “Kartik”.&lt;br&gt;
The same hash functions are applied to “Kartik.”&lt;br&gt;
On applying the hash functions we would get the same result for obvious reasons which would fetch us the same positions inside the bit array i.e. 3,5 and 9.&lt;br&gt;
The filter checks if these positions in the bit array are set to 1.&lt;br&gt;
Oh, these indexes are already marked as 1(they are on). This means the data might be present.(Username already exists, please try using a different username).&lt;br&gt;
However, if any of the hash function results point to a position that is still 0, the filter can confidently say, “No, the data is not here.” This is because the same input, when hashed, will always give the same result, so if those positions aren’t set, the data was never added.&lt;/p&gt;

&lt;p&gt;A Bloom filter can give false positives (saying something might exist when it doesn’t), but it can never give false negatives (saying something doesn’t exist when it actually does). So, when you check for “Kartik” and all bits are 1, it means “Kartik” might exist. If even one bit is 0, the filter is sure it doesn’t exist.&lt;/p&gt;

&lt;p&gt;To minimize the number of false positives you carefully need to decide the length of the bit array to be used(within your system’s capabilities) and also the number of hash functions.&lt;/p&gt;

&lt;p&gt;Increasing the number of hash functions exponentially would result in slowing down the process but decreasing them won’t increase the speed but would result in an increased number of false positives.&lt;/p&gt;

&lt;p&gt;Read more about how to calculate the above specifications here&lt;/p&gt;

&lt;p&gt;That’s all that I know about Bloom Filters as of now. I have used it in my personal projects but not on big scale ones so the choice of using this data structure should be entirely yours. I’m attaching a link where you can experiment on this data structure and find out how many times you get a false positive?&lt;/p&gt;

&lt;p&gt;Here you go:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://llimllib.github.io/bloomfilter-tutorial/" rel="noopener noreferrer"&gt;https://llimllib.github.io/bloomfilter-tutorial/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you read it till here, I’d like you to please share your story in case you used this data structure in your experience. If not used, do consider giving it a try and if you liked this post, please like, comment and share to increase the reach. You can also follow me for more such content. I post on weekends. Thanks :)&lt;/p&gt;

</description>
      <category>bloomfilters</category>
      <category>database</category>
      <category>caching</category>
      <category>bitarray</category>
    </item>
    <item>
      <title>Encryption Symmetric</title>
      <dc:creator>Kartikey Srivastava</dc:creator>
      <pubDate>Sun, 13 Oct 2024 12:25:36 +0000</pubDate>
      <link>https://dev.to/kartikey_srivastava/encryption-symmetric-26ko</link>
      <guid>https://dev.to/kartikey_srivastava/encryption-symmetric-26ko</guid>
      <description>&lt;p&gt;In simple words, converting a readable information(plain text) into something unreadable(also known as cipher text) to protect it from anyone who isn’t supposed to see it is what is called as Encryption. Encryption involves scrambling of a plain text to produce a cipher text with the help of a key.&lt;/p&gt;

&lt;p&gt;Imagine you(Person A) want to send some physical item to a friend(Person B) sitting abroad. This thing is very personal and if it gets exposed both of you guys might get into some problem. So you pack the thing inside a box and lock it with a key. Both you and your friend have same copy of this key. You locked the box with the thing inside and send it to your friend. Your friend received the box and unlocked it with the same key he had and access the thing.&lt;/p&gt;

&lt;p&gt;In this scenario, ‘A’ did encryption(boxing) whereas ‘B’ did decryption(unboxing). Since both of the parties use the same key to both encrypt and decrypt hence this process is known as ‘Symmetric Encryption’.&lt;/p&gt;

&lt;p&gt;Below is the representation of how symmetric encryption works:&lt;/p&gt;

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

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

&lt;p&gt;The key thing to note here is that the algorithm used here is just a mathematical formula which is designed to scramble the input whereas the key is used as a part of this formula. This algorithm is generic but the key, this is what ensures the uniqueness of the scrambled data.&lt;/p&gt;

&lt;p&gt;Let’s understand one of the simplest encryption algorithm, called the Caesar Cipher.&lt;/p&gt;

&lt;p&gt;This algorithm is a very basic one which simply replaces each alphabet with its subsequent character. Simply speaking, A becomes B, B becomes C and so on.&lt;/p&gt;

&lt;p&gt;With this algorithm in play, “Hello” can become “Ifmmp” which isn’t readable hence known as the Cipher text.&lt;/p&gt;

&lt;p&gt;This is a very poor algorithm and is rarely used in the industries as we all know a simple brute force can help us determine the actual input. Who would want their credit card information to be leaked this easily?&lt;/p&gt;

&lt;p&gt;Modern encryption algorithms like AES-256 ensure proper uniqueness and hence are very secure from threats. I’ve myself used this algorithm in one of our company’s project. Considering the current computing capabilities, it could take almost a trillion year to decrypt this information.&lt;/p&gt;

&lt;p&gt;Symmetric Encryption uses the same key for encryption and decryption. Hence, its very important that the key should be kept secure. Sharing this key could lead to security issues and your data can be easily exposed.&lt;/p&gt;

&lt;p&gt;An effective strategy to use encryption algorithm is to generate the key at runtime.&lt;/p&gt;

&lt;p&gt;This means, a new key is generated each time the data needs to be encrypted or decrypted. By new key, I mean that for a single transaction the key would remain same but for every new transaction it should be unique. After the session ends, you can either drop the key(if stored in the database) or you can expire it.&lt;/p&gt;

&lt;p&gt;Symmetric Encryption is usually used for encrypting data at rest such as for files stored on a disk or a database. Databases that store sensitive information (like user credentials or payment details) often use symmetric encryption to secure that data when it is not actively being used.&lt;/p&gt;

&lt;p&gt;This is it about Symmetric encryption. In future posts, we’ll dive deeper into other encryption techniques, including asymmetric encryption as well.&lt;/p&gt;

&lt;p&gt;If you read it till here, I’d like you to please share your story in case you used this encryption algorithm in your experience. If not used, do consider giving it a try and if you liked this post, please like, comment and share to increase the reach. You can also follow me for more such content. I post on weekends. Thanks :)&lt;/p&gt;

</description>
      <category>security</category>
      <category>symmetricencryption</category>
      <category>cipher</category>
      <category>encryption</category>
    </item>
  </channel>
</rss>
