On-chain vs Off-chain
Blockchain technology provides a decentralized and immutable ledger for recording transactions and storing data proofs. However, because blockchain data is publicly accessible, it is not designed to secure sensitive information by default. Instead, blockchains are primarily used for storing hash representations or encrypted versions of data. This ensures that the ledger remains efficient, tamper-resistant, and verifiable, while larger or more sensitive data is securely managed through off-chain storage solutions.
- Blockchain Efficiency: Storing large data directly on-chain is resource-intensive and costly. Blockchains are designed to prioritize consensus, security, and scalability.
- Data Integrity: Storing hash representations of data on-chain ensures that the integrity and authenticity of the off-chain data can be verified without directly storing it.
- Access Control: Off-chain storage often incorporates mechanisms to ensure only verifiable entities can access sensitive or private metadata.
- Hybrid Storage: Combining on-chain and off-chain storage provides a balance between decentralization, cost, and performance.
Key Concepts
On-Chain Data:
On-chain data refers to data stored directly on the blockchain. Some examples with the peaq blockchain include: hashes of DID Documents, transaction metadata, storage configurations, RBAC data, and smart contract states. Data stored on the blockchain is immutable and publicly verifiable.
Benefits:
- Immutability: On-chain data is designed to be tamper-evident—once recorded, it cannot be altered. However, immutability does not automatically guarantee full security; the overall security depends on the broader context and additional safeguards.
- Verification: Storing a hash ensures the authenticity of off-chain data without compromising privacy.
- Transparency: On-chain data is publicly accessible and verifiable, promoting openness and auditability.
Off-Chain Data:
Off-chain data refers to data stored outside the blockchain (e.g., in distributed storage systems like IPFS, traditional databases (MongoDB), or cloud services). This will typically include large files, metadata, or sensitive information since the data is too large or too sensitive to be stored on a public blockchain. Typically the off-chain storage is accessible and controlled through cryptographic mechanisms or decentralized identifiers.
Benefits:
- Scalability: Reduces blockchain bloat by storing large or complex data elsewhere.
- Flexibility: Allows for dynamic updates to metadata without altering on-chain records.
- Privacy: Sensitive data can be encrypted and shared with authorized entities only.
Example Use Case: DID Document
- On-Chain: Store the hash of the DID Document along with its basic details.
- Off-Chain: Store the metadata (e.g., entity metadata too large for DID Document) in an off-chain storage solution.
- Access Control: Ensure only authorized entities can access the off-chain services via verifiable credentials or permissions.
To lean more how to use IPFS or MongoDB with a DID Document please checkout the tutorial: Off-Chain Storage Solutions
This hybrid approach ensures scalability, security, and privacy, enabling blockchain-based systems to handle complex data requirements efficiently.