-
Notifications
You must be signed in to change notification settings - Fork 0
User Registry Scalability
// Current implementation (NOT SCALABLE):
class UserRegistryConsensus {
private:
std::map<CPubKey, OfficialUser> user_cache; // β In-memory only
std::map<uint256, EndorsementRecord> endorsement_cache; // β In-memory only
std::map<std::string, CPubKey> government_id_to_user; // β In-memory only
};For 8 Billion Users:
User Record Size:
- CPubKey: 33 bytes
- government_id_hash: 64 bytes (SHA256 hex)
- birth_currency: 8 bytes
- identity_proof_hash: 64 bytes
- endorsers (5 avg): 165 bytes (33 Γ 5)
- Other fields: ~100 bytes
Total per user: ~434 bytes
Memory Required:
8,000,000,000 users Γ 434 bytes = 3,472 GB = 3.4 TB RAM
Endorsement Records (5 per user):
40,000,000,000 endorsements Γ 200 bytes = 8 TB RAM
TOTAL MEMORY: ~11.4 TB RAM β IMPOSSIBLE
Current Design Cannot Scale Beyond:
- ~10 million users (4.3 GB RAM)
- ~50 million users (21.7 GB RAM)
- ~100 million users (43.4 GB RAM)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β APPLICATION LAYER β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β UserRegistryConsensus (API Layer) β
β - RegisterUser() β
β - SubmitEndorsement() β
β - GetVerifiedUsers() β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CACHE LAYER (In-Memory for Performance) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β LRU Cache (100K most recent users) β
β - Hot data in RAM β
β - Fast lookups for active users β
β - Automatic eviction of cold data β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β DATABASE LAYER (Persistent Storage) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β LevelDB / RocksDB β
β - Key-Value store (like Bitcoin Core uses) β
β - Efficient disk storage β
β - Supports billions of records β
β - Built-in compression β
β - Atomic operations β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Already in Bitcoin Core: LevelDB is used for blockchain data
- Proven Scalability: Handles billions of records efficiently
- Disk-Based: Only active data in RAM
- Fast Lookups: O(log n) complexity with optimizations
- Compression: Reduces disk space by 50-70%
- Atomic Operations: ACID compliance for data integrity
// Key-Value Pairs in LevelDB:
// User Records
Key: "user:" + CPubKey (33 bytes)
Value: Serialized OfficialUser (~434 bytes)
Total: 8B Γ 467 bytes = 3.7 TB disk (compressed: ~1.5 TB)
// Government ID Index
Key: "govid:" + government_id_hash (64 bytes)
Value: CPubKey (33 bytes)
Total: 8B Γ 97 bytes = 776 GB disk (compressed: ~300 GB)
// Endorsement Records
Key: "endorse:" + uint256 (32 bytes)
Value: Serialized EndorsementRecord (~200 bytes)
Total: 40B Γ 232 bytes = 9.3 TB disk (compressed: ~3.7 TB)
// User by Currency Index
Key: "currency:" + currency_code + ":" + CPubKey
Value: 1 byte (existence marker)
Total: 8B Γ 50 bytes = 400 GB disk (compressed: ~150 GB)
TOTAL DISK SPACE: ~5.6 TB (compressed)// Only keep hot data in RAM
LRU Cache Size: 100,000 most recent users
Memory: 100,000 Γ 434 bytes = 43.4 MB
Endorsement Cache: 500,000 recent endorsements
Memory: 500,000 Γ 200 bytes = 100 MB
Index Caches: ~50 MB
TOTAL RAM: ~200 MB (vs 11.4 TB without database!)Lookup Performance:
LevelDB Read: ~1-10 microseconds
LRU Cache Hit: ~100 nanoseconds
With 90% cache hit rate:
Average lookup: 0.9 Γ 0.0001ms + 0.1 Γ 0.01ms = 0.001ms
Can handle: 1,000,000 lookups per second per node
Write Performance:
LevelDB Write: ~10-100 microseconds
Batch writes: ~1 microsecond per record
User registration: ~100 microseconds
Can handle: 10,000 registrations per second per node
| Users | Disk Space | RAM (with cache) | Lookup Time |
|---|---|---|---|
| 1M | 700 MB | 200 MB | 0.001 ms |
| 10M | 7 GB | 200 MB | 0.001 ms |
| 100M | 70 GB | 200 MB | 0.001 ms |
| 1B | 700 GB | 200 MB | 0.002 ms |
| 8B | 5.6 TB | 200 MB | 0.003 ms |
Conclusion: Scales linearly with minimal RAM increase β
class UserDatabase {
public:
// Core operations
bool StoreUser(const CPubKey& key, const OfficialUser& user);
std::optional<OfficialUser> GetUser(const CPubKey& key);
bool DeleteUser(const CPubKey& key);
// Index operations
bool IndexGovernmentID(const std::string& gov_id, const CPubKey& key);
std::optional<CPubKey> LookupByGovernmentID(const std::string& gov_id);
// Batch operations
bool StoreBatch(const std::vector<std::pair<CPubKey, OfficialUser>>& users);
std::vector<CPubKey> GetUsersByCurrency(const std::string& currency);
// Statistics
uint64_t GetTotalUsers();
uint64_t GetVerifiedUsers();
private:
std::unique_ptr<CDBWrapper> m_db; // LevelDB wrapper
LRUCache<CPubKey, OfficialUser> m_cache; // In-memory cache
};1. Create new database schema
2. Implement database wrapper
3. Add LRU cache layer
4. Migrate existing in-memory data
5. Update all access methods
6. Test with large datasets
7. Deploy gradually
1. Add bloom filters for fast existence checks
2. Implement sharding for distributed storage
3. Add read replicas for high availability
4. Optimize indexes for common queries
5. Implement background compaction
β
Pros:
- Fast lookups (O(log n))
- Simple implementation
- No database complexity
β Cons:
- Limited to ~10M users (RAM constraint)
- Data lost on restart
- Cannot scale to billions
- Single point of failure
β
Pros:
- Scales to billions of users
- Persistent storage
- Minimal RAM usage (~200 MB)
- Fast lookups (with cache)
- Distributed storage possible
- Production-ready
β Cons:
- More complex implementation
- Requires database maintenance
- Slightly slower than pure in-memory (but still fast)
Facebook (3 billion users):
- Database: MySQL + RocksDB
- RAM per server: 256 GB
- Distributed across thousands of servers
WhatsApp (2 billion users):
- Database: Custom distributed system
- Minimal RAM per user
- Horizontal scaling
Bitcoin Core (UTXO set ~100M entries):
- Database: LevelDB
- RAM: ~2-4 GB (with cache)
- Disk: ~500 GB
- Proven scalable architecture β
O Blockchain (Target: 8 billion users):
- Should use: LevelDB/RocksDB (like Bitcoin Core)
- Estimated RAM: ~200 MB (with LRU cache)
- Estimated Disk: ~5.6 TB (compressed)
- Scalable: β With proper database backend
-
Migrate to LevelDB (High Priority)
- Use Bitcoin Core's existing CDBWrapper
- Implement user database layer
- Add LRU cache for performance
- Estimated effort: 1-2 weeks
-
Add Indexing (High Priority)
- Government ID β User mapping
- Currency β Users mapping
- Country β Users mapping
- Estimated effort: 1 week
-
Implement Caching (Medium Priority)
- LRU cache for hot users
- Bloom filters for existence checks
- Estimated effort: 1 week
-
Test at Scale (High Priority)
- Generate 10M test users
- Measure performance
- Optimize bottlenecks
- Estimated effort: 1 week
-
Sharding (When > 100M users)
- Shard by country/region
- Distribute across nodes
- Estimated effort: 1 month
-
Replication (For High Availability)
- Master-slave replication
- Read replicas
- Estimated effort: 2 weeks
-
Distributed Consensus (For Global Scale)
- Partition user registry
- Cross-shard queries
- Estimated effort: 2 months
β NOT READY for 8 billion users (in-memory design) β WORKS for up to ~10 million users (prototype/testing)
MUST implement persistent database backend with:
- LevelDB/RocksDB for storage
- LRU cache for performance
- Proper indexing for fast lookups
- Compression for disk efficiency
- Sharding for distribution (at massive scale)
- Basic Database Backend: 2-3 weeks
- Production-Ready: 1-2 months
- Billion-Scale Optimizations: 3-4 months
Bitcoin Core already uses LevelDB extensively, so we can leverage existing infrastructure and expertise. The migration path is well-understood and proven.
- Acknowledge the scalability limitation
- Plan database migration (LevelDB integration)
- Implement in phases (start with basic backend)
- Test at increasing scales (1M β 10M β 100M β 1B+)
- Optimize based on real-world usage
The O Blockchain user registry needs a database backend to scale to billions of users, but this is a well-solved problem with clear implementation path using Bitcoin Core's existing LevelDB infrastructure.
Β© O International
A Nonprofit Association Focused on the Creation of a Water Price-Based Stable Coin
Association de Loi 1901 β France NumΓ©ro de Siret (French SIREN): 924 014 467 00014