SUPPORT.TWILIO.COM END OF LIFE NOTICE: This site, support.twilio.com, is scheduled to go End of Life on February 27, 2024. All Twilio Support content has been migrated to help.twilio.com, where you can continue to find helpful Support articles, API docs, and Twilio blog content, and escalate your issues to our Support team. We encourage you to update your bookmarks and begin using the new site today for all your Twilio Support needs.

What is the Event Execution Order in Segment Cloud-Mode?

Question

What is the execution order in the lifecycle of an event in Segment within cloud-mode?

 

Product

Twilio Segment

 

Environment

Segment Console

 

Answer

When an event is triggered and sent to Segment, it passes through a specific, structured sequence of processing stages before reaching its downstream destination.

Below is the exact chronological and logical pipeline from the moment an event is generated until it is successfully delivered to a final destination API:

1. Source Generation & Pre-Processing

  • Local Plugins & Middleware: Before the event is even sent over the internet, Source Middlewares and local SDK/library plugins are executed on the client side.

  • Source Capture: The event is generated by a Segment library (or API) and sent to Segment's tracking API endpoint.

2. Ingestion & Ingest Functions

  • Ingestion: The event arrives at the Segment Tracking API, and the system automatically appends metadata fields like the receivedAt timestamp. Events failing initial basic API validation are immediately dropped as "Failed on Ingest."

  • Source Insert Functions: These run as soon as events enter Segment's CDN, allowing you to transform or filter data before it is officially inserted into the source.

3. Event Deduplication

  • Deduplication Check: Segment checks the messageId field and automatically discards duplicate events within an approximate 24-hour window.

4. Protocols & Schema Validation

  • Protocols & Tracking Plans: Segment evaluates the incoming data against your connected Tracking Plan to validate the schema. Unplanned or malformed events may be blocked or flagged based on your plan's settings.

  • Source Transformations: Any source-scoped transformations are applied at this stage.

5. Filtering & Schema Controls (Source-Level)

  • Integration Filters: Segment processes the integrations object within the event payload and applies per-source schema integration filters to determine which destinations are globally blocked or permitted to receive the data.

  • Schema Event Filters: Source-level event filters are applied here to block events entirely.

6. Destination Filters

  • Destination Filtering: Segment applies destination-specific filters to conditionally block events or properties from proceeding to a specific tool. This evaluation happens before any destination-level transformations or functions are invoked.

7. Destination-Scoped Transformations

  • Destination-Level Transformations: Segment processes destination-specific transformations only after the event has successfully passed through your Destination Filters.

8. Mapping Triggers (Actions Destinations)

  • Trigger Evaluation: Segment evaluates whether the event matches the defined trigger conditions configured in your Destination Actions. The event must match this trigger condition to proceed any further in the pipeline.

9. Destination Insert Functions

  • Function Execution: If the event successfully fires the Mapping Trigger, the Destination Insert Function code is executed. These functions can perform custom enrichment, data manipulation, or internal filtering before handover.

10. Destination Mappings / Functions

  • Field Configuration & Mapping: The event is passed to the final Action Mapping configuration or custom Destination Function. Segment maps the source fields directly into the exact format required by the downstream tool's API.

11. Delivery & Retry Logic

  • API Delivery: The final, transformed payload is delivered to the destination's endpoint.

  • Retry Mechanism: If the destination rejects the event due to a temporary error (e.g., rate limits, 5xx errors), Segment automatically retries sending the event using an exponential backoff mechanism for up to 4 hours. If it permanently fails after the retry window, it is logged as a Failed Delivery.

 

Additional Information 

Please note that this pipeline specifically applies to cloud-mode (server-side) destinations. Device-mode destinations send data directly from the user's device to the destination's API, meaning they bypass server-side processing features like Source Insert Functions and cloud-mode Destination Filters.

 

Have more questions? Submit a request
Powered by Zendesk