You’ve got your inlets and outlets with data flowing smoothly, but now you’re thinking: what if I need to reshape, enrich, or completely transform this data before it reaches its destination?
Welcome to transformers—the powerful middleman that sits between your data sources and destinations, giving you complete control over how your information gets processed.
In this guide, we’ll explore what transformers are, when to use them, and walk through practical examples of both mapping and service transformers that will unlock the full potential of your data streams.
Transformers are processing components that intercept messages within your data pipeline. They allow you to modify, enrich, or restructure data as it flows through your inlet and outlet connectors.
Transformers sit strategically in your data pipeline:
Messages flow into the transformer, transformations are applied, and the modified data continues to the next stage.
NATS provides two main types of transformers, each suited for different use cases:

1. Mapping Transformers
Built-in transformers using Bloblang to reformat, convert, filter, or reshape data. Fast, lightweight, with no external dependencies. Perfect for inline transformations.
2. Service Transformers
External services that handle complex operations like database lookups, API calls, and custom business logic. Write in your preferred language and deploy wherever needed.
Your connector is sending data, but what if it arrives in the wrong format? Mapping transformers reshape, filter, and enrich your data in real-time as it moves through your pipeline.
Key Advantages:
Perfect For:
The Problem: You’re sending temperature sensor data to Google Cloud Bigtable, but the data format doesn’t match what Bigtable expects. Your connector logs show “Invalid message format” errors.
The Solution: A mapping transformer that restructures your messages on the fly.
Original Message Format:
1{2 "timestamp": "2024-10-23T10:30:00Z",3 "temperature": 72.5,4 "sensor_id": "sensor-001"5}Required Bigtable Format:
1{2 "key": "2024-10-23T10:30:00Z",3 "data": {4 "temperature": 72.5,5 "sensor_id": "sensor-001"6 }7}The Bloblang Transformation:
1root.key = this.timestamp2root.data = thisThis simple code:
Setup Highlights:
The Result: Data flows seamlessly into Bigtable with the correct format, all transformed inline without any external services.
Mapping transformers are great for inline processing, but sometimes you need more power. Service transformers handle what mapping transformers can’t:
What Service Transformers Enable:
The Architecture: Service transformers are built on NATS microservices. They listen on a NATS subject, receive messages, apply transformations, and respond with the modified data. All via NATS messaging.
The Problem: You’re using a MongoDB inlet to capture database changes, but the data includes excess metadata from MongoDB’s change stream format. You want clean, simple messages.
MongoDB Change Stream Output (with metadata):
1{2 "_id": {...},3 "operationType": "insert",4 "clusterTime": {...},5 "fullDocument": {6 "timestamp": "2024-10-23T10:30:00Z",7 "temperature": 72.5,8 "sensor_id": "sensor-001"9 },10 "ns": {...},11 "documentKey": {...}12}Desired Clean Output:
1{2 "timestamp": "2024-10-23T10:30:00Z",3 "temperature": 72.5,4 "sensor_id": "sensor-001",5 "category": "warm"6}The Solution: A Python service transformer that extracts the data you need and adds intelligent categorization.
How It Works:
temperature.analyze subjectfullDocument fieldSample Python Code Structure:
1# NATS microservice listening on temperature.analyze2def transform_message(msg):3 # Parse MongoDB change stream4 raw_data = json.loads(msg.data)5
6 # Extract the actual document7 document = raw_data.get('fullDocument', {})8
9 # Classify temperature10 temp = document.get('temperature', 0)11 if temp < 60:12 category = "cold"13 elif temp < 80:14 category = "warm"15 else:16 category = "hot"17
18 # Add classification19 document['category'] = category20
21 # Return clean message22 return json.dumps(document)Setup Highlights:
temperature.analyze)The Result: Clean, enriched data flowing through your inlet with custom business logic applied exactly where you need it.
Choose the Right Transformer Type
Use mapping transformers for fast, inline transformations. Use service transformers when you need external data access, complex logic, or language flexibility.
No Overhead, Maximum Flexibility
Mapping transformers add no latency—transformations happen inline. Service transformers leverage NATS messaging for clean, scalable architecture.
Deploy Anywhere
Service transformers can live at the edge, in the cloud, or on-premises. Deploy them wherever your architecture demands.
Language Agnostic
Write service transformers in Python, Go, Java, or whatever fits your team’s expertise and use case.
Production-Ready
Both transformer types integrate seamlessly with connector monitoring, logging, and metrics for full observability.
Mapping transformers are powered by Bloblang data transformation language. While we’ve shown simple examples here, Bloblang can handle:
Future tutorials will dive deeper into Bloblang’s capabilities for advanced data transformation scenarios.
Transformers unlock incredible power in your data pipelines, but they’re built on top of an even more fundamental concept: Synadia Workloads. A whole new series is coming to explore workloads in depth, showing you how to build, deploy, and manage microservices in the NATS ecosystem.
Together with inlets and outlets, transformers complete the data processing story—giving you full control over data ingestion, transformation, and delivery in a unified, scalable architecture.
News and content from across the community