-
Notifications
You must be signed in to change notification settings - Fork 1
Input Outputs
Microservices can receive many kinds of inputs depending on the architecture.
HTTP is just one of many.
Microservices often expose REST APIs or webhooks that clients can call.
Examples of inputs:
REST API calls with:
Query parameters
Request body (JSON, form data)
Headers (Authorization, Content-Type)
Cookies
Webhooks (incoming HTTP POSTs from external services)
Typical usage in NestJS:
@Controller('users') with methods like @Get(), @Post(), @Patch()
@Body() for DTOs (validated JSON input)
@Param() and @Query() for route and query parameters
Microservices can receive messages asynchronously via brokers such as RabbitMQ, Kafka, or NATS.
Types of messages:
Events: Fire-and-forget notifications, e.g., { event: 'user_created' }
Commands: Instructions, e.g., { cmd: 'create_user' }
RPC Requests: Request-response messages expecting a reply
Streamed data: Continuous flow of data through the broker
Key points:
Sent and received using ClientProxy in NestJS (send() for RPC, emit() for events)
Decouples microservices, enabling async processing
Microservices can be triggered by time-based inputs rather than external calls.
Examples:
Cron patterns: "0 */10 * * * *" → run every 10 minutes
NestJS @Cron() jobs
Delayed tasks in job queues (Bull, Agenda)
Use case: Regular maintenance, data processing, or periodic reporting
Microservices can process files or streams from clients or storage services.
Examples:
File uploads: images, CSVs, PDFs
Binary streams: audio/video chunks
Pipes: gzip streams, logs
Storage-triggered inputs (S3 → microservice fetches file)
Some microservices react to changes in databases rather than direct requests.
Examples:
MongoDB Change Streams: Listen for inserts, updates, deletes in collections
Postgres LISTEN/NOTIFY: Notify microservices on specific database events
Change Data Capture (CDC): Tools like Debezium emit events when rows are updated
Use case: Automatic updates, synchronization, or auditing based on DB changes
Microservices can receive real-time data from clients or other services.
Examples:
WebSocket messages
GraphQL subscriptions
Server-Sent Event (SSE) streams
Use case: Chat apps, live notifications, or live dashboards
Microservices can be triggered by events from cloud infrastructure.
Examples:
AWS EventBridge events
Google Cloud Events
Azure Event Grid
Typical triggers:
File uploaded to S3 or GCS
CloudWatch or Stackdriver alarms
Pub/Sub push messages
Microservices can be operated or triggered manually via command-line tools.
Examples:
Command-line executables: node importData.js --file users.csv
Local scripts: ./backup.sh
Admin commands: npm run migrate
Use case: Manual data imports, migrations, maintenance, or testing
A microservice can produce many types of outputs.
Microservices often respond to HTTP requests with structured responses.
Common outputs:
JSON data: Response body containing objects, arrays, or messages
Status codes: e.g., 200 OK, 201 Created, 400 Bad Request
Error messages: Standardized exceptions or custom errors
Headers & cookies: Metadata or session-related data
Use case: REST API responses for clients or other services
Microservices can send messages asynchronously to other services via brokers like RabbitMQ, Kafka, or NATS.
Types of outputs:
Events: Fire-and-forget notifications, e.g., emit({ event: 'order_created' })
Commands: Trigger actions in other services, e.g., send({ cmd: 'charge_card' })
RPC responses: Return data in response to send() requests
ACK/NACK messages: Acknowledge successful or failed message processing
Use case: Decoupled communication between services, asynchronous workflows
Database operations are also considered outputs of a microservice.
Examples:
Inserts and updates to primary databases
Audit logs for compliance or tracking
Writes to caching layers (Redis, Memcached)
Updates to search indexes (ElasticSearch, Solr)
Use case: Persisting state changes or maintaining consistency across systems
Microservices can generate or manipulate files as outputs.
Examples:
Generated PDFs or reports
Exported CSVs or spreadsheets
Images or video thumbnails
Logs written to cloud storage (S3, GCS)
Use case: Document generation, reporting, or media processing
Some outputs are delivered instantly to clients or other services.
Examples:
WebSocket messages
Server-Sent Events (SSE)
Live notifications
GraphQL subscription pushes
Use case: Live dashboards, chat systems, or real-time alerts
Microservices can trigger events or actions in cloud infrastructure.
Examples:
AWS SNS notifications
Google Pub/Sub messages
EventBridge events
Lambda function triggers
Use case: Event-driven cloud workflows, serverless pipelines
Monitoring and observability are also outputs.
Examples:
Logs: Messages about what happened inside the service. Sent to log aggregators like ELK or Loki.
Metrics: Numerical data about performance or usage (e.g., requests/sec, error rates). Scraped by tools like Prometheus.
Traces: Data about how requests propagate through distributed systems (e.g., latency, service calls). Collected by tools like OpenTelemetry.
Alerts: Notifications generated based on thresholds in metrics or logs (e.g., “CPU > 90%”).
Use case: Monitoring, performance analysis, and debugging
Some microservices interact with external systems or users as part of their output.
Examples:
Sending emails or push notifications
SMS alerts
Third-party API calls (e.g., payment processing via Stripe, sending data to CRM)
External side effects are outputs, not HTTP responses
Use case: User communication, external integrations, or side-effect operations