Overview
This guide covers best practices for integrating S2 into your applications, whether using the cloud service or self-hosting S2 Lite.Connection Management
Reuse SDK Clients
Create SDK clients once and reuse them across your application. Clients maintain connection pools and internal state.Configure Timeouts
Set appropriate timeouts for your use case:Basin and Stream Configuration
Enable Auto-Creation
For development and testing, enable automatic stream creation:Use Descriptive Names
Choose clear, descriptive names for basins and streams:Name Validation
Basin and stream names must:- Be 1-63 characters long
- Contain only lowercase letters, numbers, and hyphens
- Start and end with a letter or number
- Not contain consecutive hyphens
Writing Data
Batch Records
Batch multiple records in a single append for better throughput:S2 processes batches atomically - all records in a batch succeed or fail together.
Use the Producer API
For high-throughput scenarios, use the Producer API which handles batching and pipelining automatically:Handle Errors
Always handle append errors appropriately:Reading Data
Use Streaming Sessions
For continuous reading, use streaming sessions instead of polling:Set Appropriate Read Limits
Control how much data you read:Use Checkpoints
Store the last processed sequence number to resume reading:S2 Lite Specific
Storage Backend Selection
In-Memory (Development/Testing)
Local Disk (Single-Node Development)
Local disk mode is not suitable for production as it lacks durability guarantees.
Object Storage (Production)
Resource Limits
When deploying S2 Lite, set appropriate resource limits:Environment Variables
SlateDB Configuration
Performance Tuning
Logging
Deployment Patterns
Single Instance
Simplest deployment for small workloads:S2 Lite is a single-node binary. For high availability, use the S2 cloud service.
Kubernetes with Helm
Security
Access Tokens
Cloud Service:TLS/HTTPS
For S2 Lite in production, enable TLS:Network Isolation
Deploy S2 Lite in a private network:SDK Compatibility
Ensure you’re using compatible SDK versions:S2 Lite requires the
S2-Basin header for stream operations. SDKs handle this automatically.Performance Optimization
Benchmark Your Workload
Use the built-in benchmark tool:Optimize Batch Sizes
Find the optimal batch size for your workload:- Too small: Higher overhead from API calls
- Too large: Higher latency, more memory usage
- Recommended: 10-100 records or 10KB-1MB per batch
Monitor Metrics
Track these key metrics:- Append latency (P95, P99)
- Batch sizes (records and bytes)
- Error rates
- Throughput (records/sec, bytes/sec)
Error Handling
Retry Logic
Implement exponential backoff for transient errors:Circuit Breaker Pattern
For high-availability systems, implement circuit breakers to prevent cascading failures.Testing
Use In-Memory S2 Lite
Always test against in-memory S2 Lite:Separate Test Basins
Use separate basins for different environments:Clean Up Test Data
Migration and Compatibility
Migrating from Development to Production
- Switch from in-memory to object storage
- Enable TLS/HTTPS
- Disable auto-creation of streams
- Configure monitoring and alerting
- Set up automated backups (object storage handles this)
- Review resource limits