Developer Platform•v1.0.0•2 min read
CRUD Order of Operations & Lifecycle Guide
Precise execution sequence of permission evaluations, before/after triggers, database transactions, and async background workers during CRUD mutations.
Understanding the precise sequence of events during a data operation is crucial for debugging, extending functionality, and building reliable automations. This document outlines the step-by-step process the system follows for every Create, Update, and Delete action on a record.
1. Core Concepts
The system's logic is enhanced by two types of customizable actions that run during a CRUD operation: Record Triggers and Record Trigger Automations.
- Record Triggers: Python scripts (
.pyfiles) executed via the Platform Context for maximum flexibility and custom code logic. - Record Trigger Automations: No-code/low-code workflows built directly in the Flow Builder UI.
Both Triggers and Automations execute within specific lifecycle stages:
- Before: Runs synchronously before the record is written to the database. Use this to validate data, enforce business constraints, or modify values in-place.
- After: Runs synchronously immediately after the record is committed to the database. Ideal for modifying related records, creating logs, or emitting side effects.
- Async: Runs asynchronously in background workers after the HTTP response has returned to the client.
2. Create Operation Sequence
Rendering diagram...
3. Update Operation Sequence
- Schema & Model Loading: Loads target object schema.
- Fetch Old State (
old_map): Retrieves the existing database record state prior to mutation. - Field & Object Permissions: Verifies update rights across all modified payload fields.
- Data Merging: Merges incoming fields with existing attributes.
- Before Update Triggers: Runs synchronous Python triggers (
context.is_changed()checks). - Database Commit: Commits merged document to tenant MongoDB collection.
- After Update Triggers: Executes synchronous side effects.
- Cache Invalidation & Async Tasks: Enqueues background worker tasks and flushes Redis caches.