RPC Queries Guide
Warning: Storage Programs are still being developed; this documentation is a preview and might not work correctly.Learn how to efficiently read data from Storage Programs using RPC queries.
Overview
Storage Program reads are served via RPC. They complete without a transaction, so there is no gas fee and responses typically arrive in under 100 ms. Writes still require consensus transactions; this guide focuses only on the read path.Basic RPC Queries
Read All Data
Read Specific Key
Performance Optimization
Batch Queries
Read multiple storage programs in parallel:- Sequential: 3 queries × 100ms = 300ms
- Parallel: max(100ms, 100ms, 100ms) = 100ms
- 3× faster
Selective Key Reading
Only read the keys you need:- Reduced bandwidth
- Faster response (less data transferred)
- Lower memory usage client-side
Caching Strategies
Simple In-Memory Cache
Cache with Metadata Tracking
Query Patterns
Polling for Updates
Conditional Reading
Pagination Pattern
For large datasets stored in arrays:Access Control and Queries
Public Queries (No Auth)
Private Queries (Auth Required)
Restricted Queries
Error Handling
Robust Query Pattern
Handling Non-Existent Keys
Advanced Patterns
Query Aggregation
Aggregate data from multiple storage programs:Query Filtering
Client-side filtering for complex queries:Subscription Pattern (WebSocket-like)
Simulate subscriptions using polling:Performance Benchmarks
Query Response Times
Typical response times for RPC queries:| Operation | Response Time | Bandwidth |
|---|---|---|
| Read metadata only | 20-50ms | ~1KB |
| Read single key | 30-80ms | Varies |
| Read all data (small, less than 1KB) | 40-100ms | ~1-2KB |
| Read all data (medium ~10KB) | 60-150ms | ~10-12KB |
| Read all data (large ~100KB) | 100-300ms | ~100-102KB |
Optimization Impact
| Technique | Speed Improvement | Use Case |
|---|---|---|
| Selective key reading | 2-3× faster | When you need specific fields |
| Parallel queries | 3-10× faster | Multiple storage programs |
| Client-side caching | 100-1000× faster | Frequently accessed data |
| Metadata-based caching | 10-50× faster | Change detection |
Best Practices
1. Read Only What You Need
2. Use Parallel Queries
3. Implement Caching
4. Handle Errors Gracefully
5. Monitor Query Performance
Next Steps
- Examples - Real-world query patterns and use cases
- API Reference - Complete API documentation
- Operations Guide - Learn about write operations