DEV Community

Hanzla Baig
Hanzla Baig

Posted on • Originally published at dev.to on

Assassin ⚡️ - An open source, free database for killing slow webpages

Assassin ⚡️ - kill slow webpages

Assassin works to kill database transactions that block the UI.

Database operations can be slow, but no existing databases solve this problem the obvious way: outsource difficult tasks to web workers.

diagram

I wanted to make a database that is:

  • Open source
  • Responsive
  • Decentralized
  • Optimized for web workers
  • Designed for private browsing

That's why I created my own database with JavaScript.

Features 💥

💫 Lightweight : Shipped with less than 100 lines of client side code.

⚖️ Decentralized : Your database has no single point of failure. If the server goes down, your data is easy to retrieve.

💎 Works in private browsing : I researched databases like LevelDB, PouchDB, and Gun, which rely on IndexedDB for client-side storage. I wanted these databases to be effective, but I ended up creating this database partly because IndexedDB is disabled in private browsing, which means none of these databases work for me.

Methods:

  • killer.connect(url) - Connect to the server.
  • killer.create(key,value) - Add an entry to the database.
  • killer.update(key,new value) - Update the value of a key in the database.
  • killer.delete(key) - Delete an entry in the database.
  • Read the database - Inside a web worker or the main thread, you can access the database through the variable called database.

Architecture:

  • Data Model : Assassin is a key/value store that supports mapping a key to its corresponding value.
  • System Architecture : The DAT protocol distributes and hosts data between many computers, so there is no one location where data is stored. Assassin relies on the the DAT protocol for data persistence. The metadata of the key-value pairs are stored in a distributed trie structure.
  • Isolation Levels : The isolation level is determined by the end user of the database. Assassin is designed to have a low isolation level.
  • Storage Model : Assassin sends data to the server, which then stores the metadata in the distributed file system Hyperdrive, which is built on the DAT protocol. The data itself is distributed and hosted between multiple peers.
  • Highly Available : Assassin is highly available and eventually consistent. Assassin always saves the last edits made to the database when conflicts arise. This CRDT may change later.

Why is it called Assassin?

  • My personal website currently uses the Gun database.
  • Gun has many features I like and the founder is pretty nice.
  • Gun stopped working for me.
  • Gun's storage adapter RAD relies on IndexedDB, which is disabled in private browsing.
  • Gun syncs data peer to peer through WebRTC, which doesn't work in web workers.
  • Assassin is sort of (seriously, very little) like Gun but for web workers.
  • Gun + worker = Assassin 💥

Built with 🔧

  • Hyperdrive - Thanks for building an abstraction layer on top of the DAT protocol!
  • HTML - For creating the web demo
  • CSS - For styling the web demo
  • JavaScript - For logic
  • Node.js - To serve the logic

Make sure to share your opinion on:

And if you really want to help make Assassin better, contribute to the GitHub repo!

Assassin is open source, and always will be.

Support me on:

Star the repo on GitHub, Tweet, and share among your friends, teams and contacts!

Top comments (5)

Collapse
 
miketalbot profile image
Mike Talbot ⭐

How does the decentralisation work?

Collapse
 
devtostd profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct
Dev Studio

Decentralization in computing refers to the distribution of data and computational processes across multiple nodes or devices, rather than relying on a central server or authority. This concept is pivotal in creating more resilient, scalable, and privacy-preserving systems. To understand how decentralization works, we can break it down into key components and examine it with examples.

Core Concepts of Decentralization

  1. Distributed Data Storage:
    • Centralized System: In a traditional setup, data is stored on a central server. All clients (users) interact with this server to retrieve or store data.
    • Decentralized System: Data is spread across multiple nodes (computers or servers), with each node maintaining a portion of the overall data. This distribution ensures that no single point of failure exists.

Example:

  • Centralized: A social media platform stores user data on its own servers. If the server goes down, users cannot access their data.
  • Decentralized: In a decentralized platform like Mastodon, user data is distributed across multiple servers (instances). If one instance goes down, others remain operational, and data can often be recovered or accessed from other nodes.
  1. Peer-to-Peer (P2P) Networking:
    • Decentralization often relies on P2P networks, where each participant (peer) acts as both a client and a server. This model allows data and resources to be shared directly between peers without needing a central intermediary.

Example:

  • BitTorrent: When downloading a file using BitTorrent, the file is split into chunks distributed across many users. Each user downloads chunks from others and uploads chunks they already have, creating a resilient and efficient distribution system.
  1. Consensus Mechanisms:
    • Decentralized systems require methods to ensure data consistency across all nodes. Consensus mechanisms help nodes agree on the state of the system without a central authority.

Example:

  • Blockchain: In cryptocurrencies like Bitcoin, a consensus mechanism called Proof of Work (PoW) ensures that all participants agree on the state of the blockchain (a decentralized ledger). This prevents double-spending and ensures data integrity.
  1. Fault Tolerance and Redundancy:
    • In a decentralized system, if one node fails, others can continue to operate, making the system more robust against failures and attacks.

Example:

  • IPFS (InterPlanetary File System): IPFS stores files across multiple nodes. If one node holding a file goes offline, the file can still be retrieved from other nodes that have a copy, ensuring high availability.

Benefits of Decentralization

  • Resilience: With no single point of failure, decentralized systems are more resistant to outages and attacks.
  • Scalability: Decentralized systems can scale more efficiently by adding more nodes to the network.
  • Privacy: Users have more control over their data since it’s not stored on a central server that could be breached or misused.
  • Censorship Resistance: Without a central authority, it’s harder to censor or control the information flow in a decentralized system.

Challenges of Decentralization

  • Complexity: Managing a decentralized system is more complex due to the need for consensus mechanisms and ensuring data consistency.
  • Performance: Decentralized systems can sometimes be slower due to the overhead of maintaining consensus and data synchronization.
  • Resource Usage: Each node in a decentralized network needs to store data and perform computations, which can lead to higher resource usage compared to a centralized system.

Practical Example: Decentralized Database (Assassin)

In the context of the Assassin project mentioned in the Dev.to post, decentralization is achieved by distributing database operations across multiple web workers using the DAT protocol. Here's how it works:

  1. Data Distribution: Instead of a central server, Assassin stores data across multiple peers using the Hyperdrive file system. Each peer contributes to storing and sharing the data, ensuring no single point of failure.

  2. Web Workers: By offloading database operations to web workers, Assassin reduces the load on the main thread, enhancing the performance of web pages by handling data operations in the background.

  3. Example in Action:

    • A user interacts with a webpage that uses Assassin. When the user performs an action (e.g., saving a form), the data is stored locally and synchronized with other peers in the network. Even if the main server or one of the peers goes offline, the data remains accessible through other peers.

Conclusion

Decentralization transforms how systems operate by distributing control, data, and processes. It offers numerous benefits, especially in terms of resilience, privacy, and scalability, but also introduces challenges that need careful management. Projects like Assassin demonstrate the practical application of decentralization, making web pages faster and more reliable by leveraging distributed data storage and processing.

Collapse
 
programmerraja profile image
Boopathi

Interesting approach to database design, especially for web workers and private browsing.

The distributed architecture and DAT protocol integration seem promising.

Collapse
 
devtostd profile image
Dev Studio

Thanks 👍

Collapse
 
jnv profile image
Jan Vlnas

Too bad the project seems abandoned (last commit 5 years ago and the original article is from 2020).

Some comments may only be visible to logged-in visitors. Sign in to view all comments.