Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Bloom filters for system design interviews, explained

Bloom filters for system design interviews, explained Somewhere in a design — a cache in front of a database, an LSM-tree storage engine, a web crawler deduplicating URLs — you hit the same waste: you keep doing an expensive lookup only to find the thing is not there . A bloom filter is the trick that kills that waste. It is a tiny, probabilistic structure that answers one question — is this item…

Bloom filters are a valuable tool in system design interviews, particularly when faced with the need to avoid costly lookups for non-existent items. They offer a solution by providing a compact, probabilistic structure that answers the question of whether an item is in a set with two possible outcomes: "definitely not" or "probably yes."

When the filter asserts "definitely not," it allows you to bypass the expensive lookup entirely. The key advantage of bloom filters lies in their ability to minimize false negatives while accepting a small chance of false positives. This asymmetric error pattern makes them particularly useful in read-heavy systems where most lookups are for non-existent items.

The guide outlines the structure of a bloom filter, which consists of a bit array initialized to all zeros and a set of k hash functions that map items to positions within the array. Adding an item involves running it through all k hash functions to determine k positions, and then setting those bits to 1. Checking an item follows the same process, and if any of the bits are 0, the item is definitely not present in the set.

However, if all k bits are 1, the item is probably present, but this is only a probable yes, not a definitive one. The guide emphasizes that while bloom filters guarantee no false negatives, they can occasionally produce false positives. These false positives occur when the bits for a nonexistent item happen to be set by the hashes of other items, resulting in a "probably yes" response.

Despite this, the false positive rate can be controlled by adjusting the size of the bit array and the number of hash functions used. The guide also highlights the interviewer's focus on understanding the guarantee of no false negatives and the ability to explain the trade-off between memory usage and false positive rate. It is crucial to grasp the concept, communicate the key properties concisely, and demonstrate a clear understanding of when and how to effectively employ bloom filters in system design decisions.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

Python: String

Python Notes: Strings, Lists, Loops 1. What is a String? A string is a datatype, written as str in Python. It is a collection of characters: alphabets, special characters and numbers.

  • String is a datatype in Python, denoted as str.
  • Strings are enclosed in single or double quotes, triple quotes for multiline.
  • Strings are immutable, cannot be changed once created.

Implementing HIPAA Safe Harbor (45 CFR § 164.514(b)(2)) CSV De-Identification 100% Client-Side in Vanilla JS

If you have ever tried to help a hospital lab, MD/PhD student, or clinical data team share a research CSV with an external collaborator or journal repository, you know the catch-22: Cloud SaaS…

  • HIPAA Safe Harbor 18-identifier transformation occurs client-side in Vanilla JS
  • ZIP codes and ages require specific handling per 45 CFR § 164.514(b)(2)
  • Audit certificates generated via SHA-256 fingerprints for data verification

More from Monday 23 November →