Skip to main content

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:
For long-running streaming sessions, use higher timeouts or configure the timeout specifically for read operations.

Basin and Stream Configuration

Enable Auto-Creation

For development and testing, enable automatic stream creation:
In production, disable auto-creation and explicitly create streams. This prevents typos from creating unwanted streams.

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:
The Producer API automatically batches records and uses pipelining for optimal performance.

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)

Perfect for integration tests and local development.

Local Disk (Single-Node Development)

Local disk mode is not suitable for production as it lacks durability guarantees.

Object Storage (Production)

Always use object storage for production deployments to ensure data durability.

Resource Limits

When deploying S2 Lite, set appropriate resource limits:

Environment Variables

SlateDB Configuration

For production with object storage, use 50ms (default). For in-memory testing, use 5ms (default).

Performance Tuning

Pipelining is currently disabled by default. Only enable in non-critical environments.

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:
S2 Lite:
S2 Lite does not validate access tokens. Use network-level security (VPC, firewall rules) to protect your S2 Lite instances.

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:
  1. Append latency (P95, P99)
  2. Batch sizes (records and bytes)
  3. Error rates
  4. 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

  1. Switch from in-memory to object storage
  2. Enable TLS/HTTPS
  3. Disable auto-creation of streams
  4. Configure monitoring and alerting
  5. Set up automated backups (object storage handles this)
  6. Review resource limits

Cloud to Self-Hosted (or vice versa)

Both use the same API, so only configuration changes are needed: