Creates daily snapshots of all balances in batches. Balance snapshots enable efficient historical balance queries by capturing point-in-time states, eliminating the need to replay all transactions when retrieving historical data.
Query Parameters
The number of balances to process in each batch. Larger batch sizes are faster but use more memory. Recommended:
Small databases: 1000-5000
Medium databases: 500-1000
Large databases: 100-500
Example: ?batch_size=2000
Response
Status message indicating the snapshot operation has started.
How It Works
Asynchronous Processing
The snapshot operation runs asynchronously in the background:
Request Initiated : API accepts the request and returns immediately
Background Processing : Snapshots are created in batches
Progress Logging : Operation progress is logged to system logs
Completion : Message logged when all snapshots are created
Snapshot Creation Process
1. Fetch balances in batches (controlled by batch_size)
2. For each balance:
- Record current balance state
- Capture debit_balance, credit_balance
- Store timestamp
- Save to snapshot table
3. Continue until all balances are processed
4. Log completion with metrics
Examples
Default Batch Size
Custom Batch Size
Small Batch (Conservative)
Large Batch (Fast)
curl -X POST https://api.blnk.io/balances-snapshots \
-H "Authorization: Bearer YOUR_API_KEY"
{
"message" : "Snapshotting in progress. should be completed shortly"
}
Use Cases
Daily Snapshots
Run at end of business day to capture daily balance states:
# Daily cron job at 11:59 PM
59 23 * * * curl -X POST https://api.blnk.io/balances-snapshots
Month-End Processing
Create snapshots before month-end close:
# Last day of month
curl -X POST https://api.blnk.io/balances-snapshots?batch_size= 5000
Before Major Reports
Ensure snapshots are current before generating historical reports:
# Before running reports
curl -X POST https://api.blnk.io/balances-snapshots
# Wait for completion, then run reports
curl "GET https://api.blnk.io/balances/bal_123/at?timestamp=2024-01-31T23:59:59Z"
System Maintenance
Create snapshots before system maintenance windows:
curl -X POST https://api.blnk.io/balances-snapshots?batch_size= 1000
Scheduling Snapshots
Cron Job (Linux/macOS)
# Edit crontab
crontab -e
# Add daily snapshot at midnight
0 0 * * * curl -X POST https://api.blnk.io/balances-snapshots
# Add snapshot every 6 hours
0 * /6 * * * curl -X POST https://api.blnk.io/balances-snapshots?batch_size= 2000
Scheduled Task (Windows)
# Create scheduled task for daily snapshots
schtasks / create / tn "Balance Snapshots" / tr "curl -X POST https://api.blnk.io/balances-snapshots" / sc daily / st 00 : 00
Cloud Functions/Lambda
// AWS Lambda / Cloud Function example
export const handler = async ( event ) => {
const response = await fetch ( 'https://api.blnk.io/balances-snapshots' , {
method: 'POST' ,
headers: {
'Authorization' : `Bearer ${ process . env . BLNK_API_KEY } `
}
});
return {
statusCode: 200 ,
body: JSON . stringify ( await response . json ())
};
};
Batch Size Guidelines
Small Database (<10,000 balances):
curl -X POST "https://api.blnk.io/balances-snapshots?batch_size=5000"
Medium Database (10,000-100,000 balances):
curl -X POST "https://api.blnk.io/balances-snapshots?batch_size=1000"
Large Database (>100,000 balances):
curl -X POST "https://api.blnk.io/balances-snapshots?batch_size=500"
Very Large Database (>1,000,000 balances):
curl -X POST "https://api.blnk.io/balances-snapshots?batch_size=100"
Monitoring Progress
Check application logs for progress updates:
{
"level" : "info" ,
"msg" : "Balance snapshot operation starting" ,
"batch_size" : 1000 ,
"operation" : "balance_snapshots" ,
"status" : "started" ,
"timestamp" : "2024-01-15T00:00:00Z"
}
{
"level" : "info" ,
"msg" : "Balance snapshot operation completed successfully" ,
"batch_size" : 1000 ,
"operation" : "balance_snapshots" ,
"status" : "completed" ,
"total_snapshots" : 45230 ,
"duration_ms" : 12450 ,
"snapshots_per_second" : 3632.5 ,
"timestamp" : "2024-01-15T00:00:12Z"
}
Benefits of Snapshots
Faster Historical Queries
Retrieve historical balance states in milliseconds
No need to replay thousands of transactions
Optimized database queries
Reduced Database Load
Fewer complex joins and aggregations
Lower CPU and memory usage
Better performance for concurrent queries
Audit and Compliance
Point-in-time balance verification
Regulatory reporting requirements
Historical data preservation
Recovery and Reconciliation
Quick balance verification
Discrepancy detection
Data integrity checks
Best Practices
Schedule Daily : Create snapshots at least once per day
Off-Peak Hours : Run during low-traffic periods
Monitor Performance : Track snapshot creation metrics
Tune Batch Size : Adjust based on database size and performance
Retention Policy : Define how long to keep snapshots (e.g., 2 years)
Validate Results : Periodically verify snapshot accuracy
Snapshot Storage
Snapshots are stored efficiently:
Indexed by balance_id and timestamp
Compressed for storage efficiency
Queryable via the Get Balance at Time endpoint
Automatically used for historical queries