Writing Event-Driven Serverless Code to Build Scalable Applications
A practical introduction to event-driven serverless architecture, using Appwrite Functions to send welcome emails when users are created. It explains how independently triggered functions reduce infrastructure overhead and scale according to demand.
Writing Event-Driven Serverless Code to Build Scalable Applications
Author: Chirag Aggarwal | Published: 2025-01-26 | Generated: 2025-01-26 | Domain: dev.to
Tags: ‘#serverless’ ‘#event-driven’ ‘#appwrite’ ‘#nodejs’ ‘#cloud-architecture’
TLDR
Serverless means delegating server provisioning, patching, security, and elastic scaling to a cloud provider—not eliminating servers altogether. The article advocates decomposing selected application tasks into independently triggered functions so infrequent work, such as a welcome email, does not consume the same always-on resources as high-traffic paths. It demonstrates this pattern with Appwrite: a
users.*.createevent invokes a Node.js function that uses Resend to email each newly created user.
Key Takeaways
- Serverless shifts operational responsibility: Cloud providers run the infrastructure while developers focus on application code; self-managed VPS or hardware still requires patching, networking, SSL, security, and scaling work.
- Functions enable independent scaling: Breaking work into small, event-triggered units lets high-frequency features and infrequent background tasks consume resources on separate demand curves, reducing overprovisioning.
- Appwrite provides an integrated backend: Its open-source BaaS combines authentication, databases, storage, and functions, avoiding the need to assemble separate cloud services for a basic event-driven workflow.
- The example uses Node 20 and Appwrite tooling: Initialize a project with
appwrite init, create a function viaappwrite init function, then deploy it withappwrite push functions. - User creation triggers email delivery: The function listens for Appwrite’s
users.*.createevent, readsreq.body.email, and calls Resend’s email API. Resend requires an API key and a connected sending domain.
Images & Media
- Cover image for Writing Event-Driven Serverless Code to Build Scalable Applications — Article cover illustration.
- Serverless Deployment Diagram — Illustrates deploying code to a cloud provider that manages infrastructure.
- Functions Diagram — Shows application concerns divided into discrete functions.
- Function Deployment Options — Compares serverless function deployment platforms.
- Functions Architecture — Depicts the user-creation and email-function workflow.
- Appwrite Console showing Events — Appwrite console configuration for attaching the
users.*.createevent. - Conclusion Image — Closing serverless illustration.
Referenced Links
- Original article on Chirag Aggarwal’s site — Original publication.
- Appwrite — Open-source backend platform used for authentication and functions.
- Appwrite CLI installation documentation — Setup instructions for the CLI.
- Appwrite platform events documentation — Reference for configuring event-driven function triggers.
- Resend — Email service used by the demonstration function.
- Resend documentation — Setup and sending-domain requirements for Resend.