Service, function, event, and trigger are the basic elements of Function Compute.
A service instance, or service for short, is the basic unit of Function Compute resource, and it organizes a group of functions that are designed for a common task purpose. You can set up access policies, configure log settings, or create functions for a service. All the functions within a service share the same settings. A function belongs to only one service.
When you get started with Function Compute to develop an application, you can set all the functions to a single service at first. However, with the growth of the number of functions and the complexity of your application, we recommend that you consider using the micro-service architecture and split your application into multiple services. For example, supposing that you are developing a blog application, you can split it into services such as UserService, PostService, CommentService, and so on. Each service contains several specific functions that assume a sub-task, which enables each service can be independently developed, tested, and deployed. In particular:
- UserService manages your user resource and databases to provide creating, reading, updating, and deleting operation.
- PostService manages the post requests and databases to provide creating, reading, updating, and deleting operation.
- CommentService manages the comment requests and databases to provide creating, reading, updating, and deleting operation.
A function is a basic unit in scheduling and operating a specified task, and itself is a piece of code that is written and uploaded by you. A function runs when it is either invoked directly or triggered by a pre-configured event. The number of functions that can be created in a service is limited. For more information, see Limits.
An event is an action that triggers the invocation of a function. For example, an HTTP request to call a function or an operation that uploads an object to a specified OSS bucket and triggers a function can be regarded as an event.
A trigger determines whether a function is called or not for some events. You can create a trigger to configure, recognize, and monitor a set of events. For example, if you create an OSS PutObject trigger, when an object is put to a specified OSS bucket, a function is invoked to process the pre-defined event.