/
Data engineering

Filter Transform Route Data in Real Time with Functions

Discover Stacksync's embedded functions for real-time filtering, transformation, and routing of data changes in bi-directional sync pipelines with microsecond latency.

Filter Transform Route Data in Real Time with Functions

Modern enterprises implementing real-time data synchronization face a fundamental challenge: efficiently processing massive volumes of database changes while applying business logic in operational pipelines. Traditional CDC approaches struggle to deliver filtering, transformation, and routing capabilities at the sub-millisecond latency that operational systems demand [1].

Stacksync addresses this technical constraint by embedding custom processing functions directly within bi-directional synchronization pipelines, enabling organizations to filter, transform, and route data changes in single-digit microseconds without compromising reliability or consistency.

Why Functions Are Essential for Real-Time Data Sync

Stacksync powers real-time and two-way sync between CRMs, ERPs and databases, allowing engineers to sync and consolidate data at scale while focusing on business logic rather than API infrastructure . Within these high-throughput pipelines, three fundamental operations consistently emerge:

Filter: Organizations require specific database changes based on inclusion criteria, exclusion rules, or complex conditional logic—not every modification captured by CDC systems [2]. Processing unnecessary events downstream creates inefficiencies across entire synchronization architectures.

Transform: Raw database payloads rarely match target system requirements. Operational systems need PII redaction, timestamp reformatting, field derivation, and data normalization—all with sub-second latency [3].

Route: Modern data architectures require intelligent distribution of events to specific destinations based on content analysis, metadata evaluation, or business rules [4].

Applying this logic downstream through separate services adds latency, overhead, and architectural complexity that undermines real-time operational capabilities [5]. Database triggers increase source system load, while configuration-based rules lack the flexibility for complex processing requirements.

Stacksync's unified function primitive addresses all three operations using the same interface, eliminating multiple tool dependencies while delivering enterprise-grade performance.

Function Examples: Real-Time Processing in Action

Filter Functions

Filter functions return boolean values to determine which database changes propagate through synchronization pipelines:

def filter(_action, record, _changes, _metadata) do
  record["region"] in ["us-west", "us-east"] and record["status"] == "active"
end

This filter processes only records from specific geographic regions with active status, eliminating downstream processing of irrelevant data while maintaining field-level precision.

Transform Functions

Transform functions reshape database changes into target-appropriate JSON structures during synchronization:

def transform(_action, record, _changes, metadata) do
 %{
   "customer_id" => record["id"],
   "email_normalized" => String.downcase(record["email"]),
   "sync_timestamp" => metadata.commit_timestamp,
   "source_table" => "#{metadata.table_schema}.#{metadata.table_name}"
 }
end

This approach creates clean, immediately usable payloads with normalized data and contextual metadata, eliminating post-processing requirements [3].

Routing Functions

Routing functions dynamically determine event destinations based on content analysis:

def route(_action, record, _changes, metadata) do
 destination = case record["priority_level"] do
   "critical" -> "alerts.high_priority"
   "standard" -> "#{metadata.table_schema}.standard"
   _ -> "events.general"
 end
 
 %{"topic" => destination}
end

This routing logic directs critical events to priority queues while maintaining standard processing flows for regular updates.

Technical Implementation: High-Performance Function Execution

Stacksync implements functions using a restricted Elixir interpreter optimized for microsecond-latency execution within high-volume CDC pipelines. This architectural choice delivers unmatched performance while maintaining operational simplicity.

Performance Requirements: Real-time data pipelines processing 50,000+ messages per second demand sub-millisecond function execution [6]. Stacksync's approach eliminates the latency penalties of external service calls or separate processing stages.

Language Selection: Most organizations haven't implemented Elixir, but complex data processing requires full programming language expressiveness rather than limited configuration options. Stacksync includes a "Copy for ChatGPT" feature providing LLMs with complete context for translating requirements into working Mini Elixir code, eliminating the learning curve.

Unified Architecture: Rather than managing multiple specialized tools for different pipeline stages, Stacksync provides a single platform engineered specifically for real-time, bi-directional data synchronization with embedded processing capabilities.

Building and Testing Functions

Stacksync integrates function development into standard engineering workflows through multiple interfaces:

Console Development: The Stacksync Console provides an integrated IDE for writing and testing functions against live data streams with immediate feedback.

Configuration as Code: Functions integrate with CI/CD pipelines through declarative configuration:

functions:
 region_filter:
   type: filter
   code: |
     def filter(_action, record, _changes, _metadata) do
       record["region"] in ["us-west", "us-east"]
     end
     
 customer_transform:
   type: transform
   code: |
     def transform(_action, record, _changes, metadata) do
       %{
         "customer_id" => record["id"],
         "email" => String.downcase(record["email"]),
         "updated_at" => metadata.commit_timestamp
       }
     end
     
 priority_router:
   type: routing
   code: |
     def route(_action, record, _changes, metadata) do
       %{
         "destination" => "#{metadata.table_schema}.#{metadata.table_name}"
       }
     end
     
syncs:
 - name: customer_pipeline
   source_table: customers
   filter: region_filter
   transform: customer_transform
   routing: priority_router
   destination:
     type: database
     connection: "postgresql://target-db"

Version Control Integration: Functions exist as plain text, enabling standard development practices including automated testing, code review, and deployment automation.

Enterprise Advantages Over Traditional Approaches

Organizations implementing Stacksync report up to 80-90% reduction in integration maintenance effort compared to custom development or point solutions. Functions extend these benefits to data processing logic:

Eliminated Infrastructure: Organizations avoid building and maintaining separate filtering, transformation, and routing services while achieving superior performance.

Unified Operations: Point solutions create complex, untraceable data flows with fragmented governance and monitoring. Stacksync provides centralized processing within the synchronization platform .

Real-Time Consistency: Stacksync's true two-way sync ensures that updates in any system instantly reflect across all connected systems , with functions processing changes at synchronization speed.

Enterprise Security: Functions operate within Stacksync's SOC 2, GDPR, HIPAA, and ISO 27001 compliance framework with enterprise-grade monitoring and error handling.

Get Started with Real-Time Data Processing

Functions are available across all Stacksync synchronization capabilities. This establishes a unified and consistent data backbone across critical business systems, automating processes that were previously manual while empowering teams with reliable, real-time information .

Implementation Process:

  1. Connect Systems: Use Stacksync's 200+ pre-built connectors to establish bi-directional synchronization
  2. Develop Functions: Create filter, transform, and routing logic using the Console IDE or configuration-as-code approach
  3. Deploy and Monitor: Activate real-time processing with comprehensive observability through Stacksync's platform dashboard

Ready to eliminate custom data processing infrastructure while achieving microsecond-latency performance? Explore how Stacksync's functions can transform your real-time data synchronization architecture without the complexity of traditional approaches.

Start building with Stacksync's real-time functions →