Daniel López Azaña

Theme

Social Media

Lightstreamer Rust Client SDK - Open Source Real-Time Messaging Library

Professional Rust client SDK for Lightstreamer real-time messaging server. Implements TLCP protocol with WebSocket support, enabling live data streaming for financial applications, IoT systems, and real-time platforms. Published on crates.io as open-source contribution to Rust ecosystem.

Available on:crates.iocrates.ioGitHub

When building real-time trading applications in Rust, I encountered a critical gap: no Rust client library existed for Lightstreamer, the industry-standard real-time messaging server used extensively in financial systems, IoT platforms, and live data applications. Rather than compromise the tech stack or implement a suboptimal workaround, I developed a professional-grade Rust client SDK and released it as open-source software to benefit the entire Rust community.

Lightstreamer Rust client SDK on crates.io

The Challenge: Real-Time Data Streaming in Rust

What is Lightstreamer?

Lightstreamer logo

Lightstreamer - Industry-standard real-time messaging server

Lightstreamer is a high-performance real-time messaging server that powers mission-critical applications across multiple industries:

Key Use Cases:

  • Financial Markets - Live stock quotes, options chains, trading data
  • IoT Systems - Sensor telemetry, device monitoring, real-time control
  • Aerospace - NASA uses Lightstreamer for ISS telemetry streaming
  • Gaming - Multiplayer game state synchronization
  • Live Updates - News feeds, social media streams, collaborative applications

Technical Capabilities:

  • Full-duplex WebSocket connections for bidirectional communication
  • Multiple transport protocols (WebSocket, HTTP streaming, long polling)
  • Bandwidth optimization with dynamic throttling and event consolidation
  • Automatic connection recovery and resilience
  • Multiple subscription modes (MERGE, DISTINCT, COMMAND, RAW)

The Gap in the Rust Ecosystem

Lightstreamer provides official client libraries for:

  • ✅ JavaScript/TypeScript
  • ✅ Java
  • ✅ .NET
  • ✅ Python
  • ✅ Objective-C/Swift
  • Rust - NONE

The Problem: Modern high-performance applications increasingly choose Rust for its exceptional concurrency, memory safety, and zero-cost abstractions. However, without a Rust client for Lightstreamer, developers faced a difficult choice:

  1. Use a different language for the Lightstreamer integration (adding complexity)
  2. Implement a custom client from scratch (expensive, time-consuming)
  3. Use an alternative messaging system (may not meet requirements)
  4. Abandon Rust for this use case (losing Rust’s benefits)

None of these options were acceptable for professional applications requiring both Rust’s performance guarantees and Lightstreamer’s proven real-time capabilities.

The Solution: A Professional Rust SDK

I developed lightstreamer-client, a comprehensive Rust SDK implementing Lightstreamer’s Text-based Live Connections Protocol (TLCP). The library provides a type-safe, asynchronous API that feels natural to Rust developers while maintaining full compatibility with Lightstreamer servers.

Architecture and Design Decisions

Core Technologies:

ComponentTechnologyPurpose
Async RuntimeTokioNon-blocking I/O and task scheduling
WebSockettokio-tungsteniteFull-duplex communication
Serializationserde/serde_jsonType-safe data handling
HTTP ClientreqwestSession creation and control requests
Error HandlingCustom error typesComprehensive error reporting

Key Technical Decisions

1. Async-First Design

The SDK is built on Tokio, Rust’s most popular async runtime:

Benefits:

  • Non-blocking operations for maximum throughput
  • Efficient handling of multiple concurrent subscriptions
  • Natural integration with async Rust applications
  • Minimal resource overhead

2. Type-Safe API

Leveraging Rust’s type system for compile-time guarantees:

pub struct LightstreamerClient {
    server_address: String,
    adapter_set: String,
    // ... internal state
}

impl LightstreamerClient {
    pub fn new(
        server_address: Option<&str>,
        adapter_set: Option<&str>,
        username: Option<&str>,
        password: Option<&str>,
    ) -> Result<Self, LightstreamerError> {
        // Validation and construction
    }
    
    pub async fn connect(&self, options: Option<ConnectionOptions>) 
        -> Result<(), LightstreamerError> {
        // Establish connection
    }
}

Advantages:

  • Compile-time prevention of invalid configurations
  • Clear API documentation through types
  • IDE autocompletion and inline documentation
  • Zero runtime overhead

3. Subscription Management

Flexible subscription system supporting all Lightstreamer modes:

pub struct Subscription {
    mode: SubscriptionMode,
    items: Option<Vec<String>>,
    fields: Option<Vec<String>>,
    // ... additional configuration
}

pub enum SubscriptionMode {
    Merge,
    Distinct,
    Raw,
    Command,
}

Features:

  • Multiple simultaneous subscriptions
  • Dynamic subscription modification
  • Automatic state management
  • Event-driven updates

Features and Capabilities

1. Full Protocol Implementation

Connection Management:

  • WebSocket-based full-duplex connections
  • Automatic session creation and management
  • Connection options configuration
  • Proxy support
  • Connection lifecycle events

Subscription Modes:

  • MERGE - Latest values for each item/field combination
  • DISTINCT - Every update delivered in sequence
  • RAW - Unfiltered data stream
  • COMMAND - Special mode for keyed data (add/update/delete)

Real-Time Updates:

  • Item update events with field values
  • Subscription status notifications
  • Connection state changes
  • Error handling and recovery

2. Production-Ready Features

Type SafetyCompile-time guarantees prevent runtime errors.
Async PerformanceNon-blocking architecture for maximum throughput.
Clean APIIdiomatic Rust interface that feels natural.
Well DocumentedComprehensive documentation and examples.

3. Real-World Application: Financial Trading

This SDK was developed to support real-time trading applications requiring professional-grade data streaming capabilities.

Requirements:

  • Real-time streaming of options market data
  • Thousands of simultaneous option contract subscriptions
  • Sub-second latency for price updates
  • Reliable connection handling with automatic recovery
  • Efficient bandwidth utilization

Results: The Lightstreamer Rust client successfully powers real-time data streaming in production trading applications, handling:

  • Multiple concurrent subscriptions to different instruments
  • High-frequency price updates with minimal latency
  • Automatic reconnection on network interruptions
  • Efficient resource utilization

Related Project

This SDK was specifically developed to support the IG Trading API Rust Client, a high-performance real-time trading application that leverages Lightstreamer for live market data streaming.

View the IG Trading API project

Open Source Contribution

Why Open Source?

Although developed for a confidential client project, I made the strategic decision to release this library as open-source software for several compelling reasons:

1. Community Benefit

  • Fills a critical gap in the Rust ecosystem
  • Enables more developers to build with Rust + Lightstreamer
  • Reduces duplication of effort across projects

2. Quality Through Collaboration

  • Community code review improves quality
  • Bug reports and contributions enhance reliability
  • Broader testing across diverse use cases

3. Industry Advancement

  • Promotes Rust adoption in real-time applications
  • Establishes best practices for TLCP implementation
  • Provides reference implementation for protocol details

Publication and Availability

Published on crates.io:

Lightstreamer client package on crates.io

Open Source Repository:

Package statistics on crates.io

Usage Example

Here’s a minimal example demonstrating the library’s clean API:

use lightstreamer_client::ls_client::LightstreamerClient;
use lightstreamer_client::subscription::{Subscription, SubscriptionMode};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create client instance
    let client = LightstreamerClient::new(
        Some("http://push.lightstreamer.com/lightstreamer"),
        Some("DEMO"),
        None, // username
        None, // password
    )?;

    // Create subscription
    let mut subscription = Subscription::new(
        SubscriptionMode::Merge,
        Some(vec!["item1".to_string(), "item2".to_string()]),
        Some(vec!["field1".to_string(), "field2".to_string()]),
    )?;

    // Subscribe to items
    client.subscribe(subscription);
    
    // Connect to server
    client.connect(None).await?;
    
    Ok(())
}

Key Features Demonstrated:

  • Simple, intuitive API
  • Type-safe configuration
  • Async/await support
  • Minimal boilerplate

Technical Achievements

First complete Rust implementation of Lightstreamer TLCP protocol.
Enabled Rust adoption for real-time financial applications.
Production-tested in financial trading systems with high-frequency data streams.
Released as open-source contribution to benefit the Rust community.

Future Development

The library provides a solid foundation with room for enhancement:

Current Focus (v0.1.x):

  • Core TLCP protocol implementation
  • WebSocket transport mode
  • MERGE subscription mode
  • Essential connection management
  • Production stability

Potential Future Enhancements:

  • Additional subscription modes (DISTINCT, RAW, COMMAND)
  • Alternative transport protocols (HTTP streaming, long polling)
  • Advanced bandwidth management
  • Connection pooling
  • Enhanced retry strategies
  • Performance optimizations

Community contributions are welcome for any of these enhancements or other improvements.

Conclusion

The Lightstreamer Rust Client SDK represents a strategic contribution to the Rust ecosystem, enabling developers to build high-performance real-time applications with one of the industry’s leading messaging platforms. By releasing this library as open-source software, I’ve helped bridge a critical gap between Rust’s capabilities and Lightstreamer’s proven technology.

This project demonstrates several key strengths:

  • Technical depth in protocol implementation and async Rust
  • Strategic thinking in identifying ecosystem gaps
  • Community focus through open-source contribution
  • Production experience with real-world financial applications

The library is actively maintained and available for any project requiring real-time data streaming with Lightstreamer and Rust.


Need Rust development or real-time systems expertise?

For projects requiring:

  • Rust system libraries and SDK development.
  • Real-time data streaming integration.
  • Financial systems with low-latency requirements.
  • WebSocket and async Rust applications.

I bring deep expertise in Rust systems programming, async architectures, and real-time applications. Available for consulting and development on similar high-performance projects.

Get in touch →

Daniel López Azaña

About the author

Daniel López Azaña

Tech entrepreneur and cloud architect with over 20 years of experience transforming infrastructures and automating processes.

Specialist in AI/LLM integration, Rust and Python development, and AWS & GCP architecture. Restless mind, idea generator, and passionate about technological innovation and AI.

Comments

Be the first to comment

Submit comment

Have a Similar Project in Mind?

Let's discuss how I can help you achieve your goals

Start a Conversation