Technical column

WebSocket Optimization: From a 46-Second Startup to Instant

December 2025

How we found the problem

In the initial design, selecting a coin subscribed to every coin over WebSocket. That led to a startup delay of about 46 seconds.

Main causes:

  • Unnecessary subscriptions: Symbols we were not trading
  • Resource waste: More connections and memory
  • Slow startup: Waiting for all subscriptions to finish
  • Poor UX: Long waits

Solution approach

1. API-based analysis for selection

Coin selection moved to API-based analysis instead of WebSocket fan-out.

  • Instant startup: APIs are asynchronous without that subscription wait
  • Only needed data: Fetch what selection actually needs
  • Caching: Reuse results

2. WebSockets dedicated to position monitoring

WebSockets are limited to monitoring symbols with open positions we actually trade.

  • Required symbols only: Subscribe to symbols with open positions
  • Dynamic subscriptions: Subscribe on open, unsubscribe on close
  • Resource savings: Drop unused subscriptions

3. Subscription retention policy

We defined clear rules for which symbols to keep versus release.

  • Baseline subscriptions: Majors (BTCUSDT, ETHUSDT) stay subscribed
  • Retention: Symbols with open positions or recent trade signals
  • Cleanup: Unsubscribe symbols that do not meet the criteria
  • Batch cleanup: Periodically prune unused subscriptions in bulk

Implementation highlights

Subscription management

Centralized subscription management improves efficiency.

  • State tracking: List of subscribed symbols
  • Priority: Important symbols first
  • Automatic cleanup: Remove unused subscriptions
  • Reconnect: Auto-reconnect and restore subscriptions after drops

Performance monitoring

We continuously monitor WebSocket performance and tune it.

  • Subscription count: Number of active symbol subscriptions
  • Memory: Related memory usage
  • Latency: Data delivery delay
  • Errors: Frequency and causes

Results

Key metrics

  • Startup time: 46s → effectively instant (~99% improvement)
  • WebSocket subscriptions: ~70% reduction
  • Memory: Lower after removing unnecessary connections
  • UX: Better with instant startup

Cost impact

  • Network: Fewer unnecessary connections
  • Server: Lower memory and CPU
  • Operations: Automated subscription hygiene

Lessons learned

1. Early design matters

Planning for performance and extensibility early pays off.

2. Resource optimization

Using only what you need is efficient.

3. Continuous monitoring

Ongoing performance monitoring surfaces the next improvements.

Government R&D and investor perspective

Technical edge

WebSocket optimization demonstrates engineering strength in system performance.

  • Performance: ~99% improvement measured in practice
  • Optimization: Problem discovery and resolution
  • Continuous improvement: Monitoring and iteration

Operational efficiency

Better performance improves operational efficiency.

  • Cost: Lower resource use
  • UX: Instant startup
  • Scale: Easier to keep performance as exchanges are added

Conclusion

WebSocket optimization improved startup from 46 seconds to effectively instant.

We achieved this through API-based selection analysis, WebSockets dedicated to position monitoring, and a clear retention policy.

For government R&D and investors, it is a strong example of engineering depth, operational efficiency, and continuous improvement.