Skip to main content
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

batch_size
integer
default:"1000"
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

message
string
Status message indicating the snapshot operation has started.

How It Works

Asynchronous Processing

The snapshot operation runs asynchronously in the background:
  1. Request Initiated: API accepts the request and returns immediately
  2. Background Processing: Snapshots are created in batches
  3. Progress Logging: Operation progress is logged to system logs
  4. 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

curl -X POST https://api.blnk.io/balances-snapshots \
  -H "Authorization: Bearer YOUR_API_KEY"
Response Example
{
  "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())
  };
};

Performance Optimization

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

  1. Schedule Daily: Create snapshots at least once per day
  2. Off-Peak Hours: Run during low-traffic periods
  3. Monitor Performance: Track snapshot creation metrics
  4. Tune Batch Size: Adjust based on database size and performance
  5. Retention Policy: Define how long to keep snapshots (e.g., 2 years)
  6. 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

Build docs developers (and LLMs) love