Technology Encyclopedia Home >What is the difference between web functions and event functions?

What is the difference between web functions and event functions?

Web functions and event functions are both types of serverless computing functions, but they serve different purposes and are triggered by different mechanisms.

Web Functions:
These are designed to handle HTTP requests, typically used for building APIs or web applications. They are directly invoked via HTTP methods (GET, POST, etc.) and return responses in formats like JSON or HTML. Web functions are ideal for serving dynamic content or processing user interactions.

Example: A web function could handle a login request, validate credentials, and return a session token.

Event Functions:
These are triggered by specific events, such as changes in a database, file uploads, or messages from a message queue. They do not expose an HTTP endpoint and are executed asynchronously when the event occurs. Event functions are useful for background tasks, data processing, or real-time notifications.

Example: An event function could process an uploaded image, resize it, and store the result in a cloud storage bucket.

In cloud computing, platforms like Tencent Cloud provide serverless solutions for both types. For web functions, Tencent Cloud SCF (Serverless Cloud Function) supports HTTP triggers, while for event functions, it can be triggered by services like COS (Object Storage), CDB (Database), or CMQ (Message Queue).