A reusable Go library for HCS (Hedera Consensus Service) timing replay. Fetch real message timing patterns from HCS topics and replay them at configurable speeds to drive realistic load tests against Hedera workloads.
Load testing Hedera applications with synthetic data produces unrealistic results. Real HCS topics have bursty, irregular message patterns that stress systems differently than uniform traffic generators.
hiero-hcs-replay captures real timing patterns from production HCS topics and replays them at any speed. Your load tests now match production behavior.
- Fetch real timing data from any public HCS topic via the Hedera Mirror Node REST API
- Replay modes: Sequential (exact reproduction) or Sample (statistically similar)
- Configurable speedup: Run tests at 1x, 10x, or any multiplier
- Zero external dependencies: Pure Go standard library (no Hedera SDK required)
- Production-ready: Comprehensive tests, CI/CD, proper error handling
go get github.com/kaldun-tech/hiero-hcs-replayRequires Go 1.21 or later.
package main
import (
"context"
"fmt"
"log"
"time"
hcsreplay "github.com/kaldun-tech/hiero-hcs-replay"
)
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
// Fetch timing data from a mainnet HCS topic
data, err := hcsreplay.FetchTiming(ctx, "0.0.120438", hcsreplay.Mainnet, 1000)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Fetched %d messages from topic %s\n", data.MessageCount, data.TopicID)
fmt.Printf("Average rate: %.2f msg/s\n", data.AvgRatePerSecond)
fmt.Printf("P50 inter-arrival: %.1fms, P99: %.1fms\n", data.Stats.P50Ms, data.Stats.P99Ms)
// Save for later use
if err := hcsreplay.SaveTiming("timing.json", data); err != nil {
log.Fatal(err)
}
}package main
import (
"fmt"
"log"
"time"
hcsreplay "github.com/kaldun-tech/hiero-hcs-replay"
)
func main() {
// Load previously saved timing data
data, err := hcsreplay.LoadTiming("timing.json")
if err != nil {
log.Fatal(err)
}
// Create replay with 10x speedup
replay := hcsreplay.NewReplay(data, hcsreplay.ModeSample, 10.0)
fmt.Printf("Effective rate: %.1f req/s\n", replay.EffectiveRate())
// Simulate load test loop
for i := 0; i < 10; i++ {
delay := replay.NextDelay()
time.Sleep(delay)
// Your operation here (API call, transaction, etc.)
fmt.Printf("Operation %d after %v delay\n", i+1, delay.Round(time.Millisecond))
}
}// Generate 1000 samples with avg=50ms, stddev=20ms (log-normal distribution)
data := hcsreplay.GenerateSynthetic(1000, 50.0, 20.0)
replay := hcsreplay.NewReplay(data, hcsreplay.ModeSample, 1.0)Contains timing distribution data from an HCS topic:
TopicID: HCS topic identifier (e.g., "0.0.120438")Network: Hedera network (mainnet, testnet, previewnet)MessageCount: Number of messages in sampleTimeSpanSeconds: Duration covered by sampleAvgRatePerSecond: Average message rateInterArrivalMs: Inter-arrival times in millisecondsStats: Statistical summary (min, max, avg, p50, p90, p99)
Stateful replay engine that produces realistic delays:
NextDelay(): Returns the next delay to waitEffectiveRate(): Returns rate after speedup appliedMode(): Returns replay modeSpeedup(): Returns speedup factor
// Fetch from public mirror node
FetchTiming(ctx, topicID, network, limit) (*TimingData, error)
// Fetch with custom options (base URL, HTTP client, progress callback)
FetchTimingWithOptions(ctx, topicID, network, limit, opts) (*TimingData, error)LoadTiming(path) (*TimingData, error)
SaveTiming(path, data) error
ReadTiming(reader) (*TimingData, error)
WriteTiming(writer, data) errorNewReplay(data, mode, speedup) *Replay
GenerateSynthetic(count, avgMs, stddevMs) *TimingData
CalculateStats(interArrivals) Statshcsreplay.Mainnet // mainnet-public.mirrornode.hedera.com
hcsreplay.Testnet // testnet.mirrornode.hedera.com
hcsreplay.Previewnet // previewnet.mirrornode.hedera.comhcsreplay.ModeSequential // Exact order, wraps around
hcsreplay.ModeSample // Random sampling from distributionSee hiero-hcs-replay-demo for a complete example that:
- Fetches timing from a real mainnet HCS topic
- Creates a test topic on Hedera testnet
- Replays timing with actual HCS message submissions
- Generates on-chain proof of activity
This demonstrates the full integration loop with the Hedera SDK.
This library was extracted from grpc-rest-benchmark, a gRPC vs REST performance benchmarking tool for Hedera workloads. See that project for a complete example of using HCS timing replay in production load tests.
| Network | Mirror Node URL |
|---|---|
| Mainnet | https://mainnet-public.mirrornode.hedera.com |
| Testnet | https://testnet.mirrornode.hedera.com |
| Previewnet | https://previewnet.mirrornode.hedera.com |
You can also use custom mirror node URLs via FetchTimingWithOptions.
How hiero-hcs-replay drives Hedera ecosystem growth:
- Developer Adoption: Lowers barrier for HCS integration testing
- Quality Assurance: Better testing → more robust dApps → higher user confidence
- TPS Generation: Load tests using real patterns generate transaction volume
- Account Creation: Test harnesses create dedicated Hedera accounts
- Target: Adopted by 50+ Hedera projects for load testing
- Each project: 10-100 test accounts, 1K-10K TPS during testing cycles
Extracted from grpc-rest-benchmark, a production benchmarking tool for Hedera workloads.
- Developed in response to developer need for realistic load testing patterns
- Follows Hedera community best practices (MIT license, DCO compliance)
- Demo topic: 0.0.8098128
- See hiero-hcs-replay-demo for live integration
- ✅ Core fetch/replay functionality
- ✅ Sequential and sample modes
- ✅ Synthetic data generation
- ✅ Comprehensive test coverage (91.7%)
- CLI wrapper for quick command-line usage
- Integration with popular Go test frameworks
- HTS token timing pattern support
- WebSocket support for live traffic capture
- Prometheus/Grafana metrics export
- Multi-topic correlation
- Submit to awesome-hedera curated list
- Publish blog post on Hedera Developer Portal
- Propose integration with Hedera Agent Kit
- Present at Hedera developer meetups
For architectural decisions and trade-offs, see DESIGN.md.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
MIT License - see LICENSE for details.
Part of the Hiero ecosystem for Hedera development tools.