Appwrite Functions: Choosing a Runtime and Trigger for Async Work
Decide between Appwrite Functions runtimes and match document, webhook, or cron triggers to your asynchronous workload.
01 Jun 2026, 06:57 UTC

The decision: runtime and trigger for asynchronous work
You need server-side code to run after a database change or on a schedule, without provisioning a virtual machine. Appwrite Functions can execute that code, but the platform supports several runtimes—Node.js, Python, PHP, Dart, and Ruby—and three trigger types: document events, HTTP webhooks, and cron schedules. Picking a combination that exceeds your timeout, lacks the right SDK permissions, or couples too tightly to the same collection it writes to can cause silent failures or infinite loops.
Useful takeaway: start with Node.js if your team already writes JavaScript, choose document triggers for reactions to data changes, use cron for scheduled maintenance, and inject secrets through environment variables rather than hardcoding them.
Constraints to set before choosing
Before comparing options, confirm these limits for your deployment:
- Timeout: maximum seconds a function may run. Differs between Appwrite Cloud plans and self-hosted configurations.
- Memory: RAM allocated per execution. Affects large payloads or heavy dependencies.
- Concurrency: how many executions can run simultaneously.
- Runtime images: self-hosted instances require Docker and must pull the Appwrite runtime image for each language you use.
Check these in the Appwrite Console under Functions settings or your self-hosted configuration before designing long-running jobs.
Trigger types compared
| Trigger | Best for | How it starts | Key risk |
|---|---|---|---|
| Document event | React to creates, updates, or deletes in a collection | Appwrite emits an event when a document matches the rule | Function writing to the same collection can loop |
| HTTP webhook | Integrations and external service callbacks | An HTTP request to the function endpoint | Requires endpoint validation and secret handling |
| Cron | Scheduled cleanup, reports, or maintenance | A time-based schedule you define | Not event-driven; schedule must be set explicitly |
Runtime selection trade-offs
Node.js is usually the default choice for asynchronous I/O because its event model fits short database calls and HTTP requests. Python is reasonable if the workload uses data-processing libraries already written in Python. PHP, Dart, and Ruby are supported, but choose them only when your team already maintains code in those languages; cross-training for a single function is rarely worth the operational overhead.
All runtimes share the same Appwrite server SDK pattern: initialize with a project API key from an environment variable, then request only the permissions the function actually needs. A function that only reads documents should not have write permission.
Example: Node.js function that processes new documents
The following sketch runs when a document is created in a monitored collection. It reads the event payload, checks whether the document is already processed to avoid duplicate work, and updates the status field. Replace placeholders with values from your project.
const { SDK } = require('node-appwrite');
module.exports = async ({ req, res, log, error }) => {
try {
const client = new SDK.Client()
.setEndpoint(process.env.APPWRITE_FUNCTION_ENDPOINT || 'https://cloud.appwrite.io/v1')
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
.setKey(process.env.APPWRITE_FUNCTION_API_KEY);
const databases = new SDK.Databases(client);
const payload = req.body || {};
log('Received event:', JSON.stringify(payload));
const event = payload.events?.[0];
const { databaseId, collectionId, documentId } = event?.metadata || {};
if (!databaseId || !collectionId || !documentId) {
return res.json({ ok: false, message: 'Missing document metadata' }, 400);
}
const document = await databases.getDocument(databaseId, collectionId, documentId);
if (document.status === 'processed') {
return res.json({ ok: true, message: 'Already processed' });
}
await databases.updateDocument(databaseId, collectionId, documentId, {
status: 'processed',
});
return res.json({ ok: true, message: 'Document marked processed' });
} catch (err) {
error('Function failed:', err.message);
return res.json({ ok: false, message: err.message }, 500);
}
};
This is an implementation sketch. Method names and the event payload shape depend on your installed Appwrite SDK version; verify them before deploying to production.
Deploy and validate
- In the Appwrite Console, create a Node.js function and add the environment variables
APPWRITE_FUNCTION_PROJECT_IDandAPPWRITE_FUNCTION_API_KEY. Use an API key with the least privilege required—read access to the target collection, plus write access only if the function updates documents. - Add a document trigger for the
createevent on the collection you want to monitor. - Deploy the function through the Console or CLI. Required permission: a project role that can create and deploy functions.
- Create a document in the monitored collection.
- Open the function's execution logs. A successful run shows the logged payload and an HTTP 200 response; the target document should have
statusset toprocessed.
Risk: if the function updates the same collection that triggers it, the update may fire the trigger again. Prevent this by checking document.status before writing, as shown above, or by targeting a different collection for the output.
Rollback: disable the document trigger in the Console or revert to the previous function deployment if executions begin failing after an update.
Limitations and how to check
Function execution is bounded by timeout and memory. A job that processes thousands of documents in one invocation may be killed. Split large workloads into smaller executions or use a queue pattern outside the function.
Event-triggered functions may retry on failure depending on your configuration. Design database writes and external API calls to be idempotent so a retry does not duplicate work.
Self-hosted deployments require Docker and the correct runtime image. If you add a new language later, pre-pull its Appwrite runtime image in air-gapped environments.
To verify your actual limits, open the function's settings in the Appwrite Console and review the timeout and memory values. Then run the minimal example above and inspect the execution log for duration and memory usage.