View Accounts

Technical Articles

Tech Articles from your friends at Oracle and the developer community.

Topics
                Topics

                Serverless functions

                Introduction

                Serverless functions are part of an evolution in cloud computing that has helped free organizations from many of the constraints of managing infrastructure and resources. They enable developers to focus on writing code for event-driven applications that respond to a variety of triggers without worrying about the underlying platform management.

                In the past, application architectures were monolithic, tightly integrated systems forming a single, comprehensive application. However, such systems were expensive and difficult to maintain, resulting in numerous cycles spent on development, redeployment, and reintegration. Businesses need to remain agile, responding to both customer and industry needs in a timely fashion. To address some of these concerns, we have seen developers gradually moving from building monolithic applications to using containers and microservices. Microservices were introduced to create isolation and modularity in development, with a suite of code blocks acting in concert to form a single application.

                Figure 1. Physical, Virtualization, Cloud Compute, Containers, Serverless

                Figure 1. Physical, Virtualization, Cloud Compute, Containers, Serverless

                In addition, cloud providers offered a way to free companies from the need to host these applications themselves. Such serverless architecture removed the burden from organizations to manage their own physical or virtual servers, as well as any of the other platform components required for the application to run. With it, businesses were provided the means to quickly adapt to the needs of their customers and allow developers to be free to focus on their code.

                What are serverless functions?

                Serverless functions are one of the inherent features of serverless computing. These functions offer targeted, on-demand, and single-purpose application functionality that runs only when triggered by preconfigured events and for the time that they’re required. This means that unlike the always-on product model of systems like database servers, you only pay for resources that you consume during function execution and nowhere else.

                Figure 2. How do Serverless Functions Works?

                Figure 2. How do Serverless Functions Works?

                As a developer, you create code for your serverless application. The serverless function code is then pushed out to a container registry. An event or a trigger is used to invoke the serverless function. When the event configured for a function occurs, the serverless function image runs as a container and executes the code. The function runs only when it is invoked, and you pay only for the resources and invocation time used by the application.

                Additionally, since these serverless functions are often hosted by the cloud provider, the organization doesn’t have to worry about managing deployments or scaling. And self-contained, easier-to-maintain code means that products can be brought to market faster, freeing developers to focus on building and maintaining their applications without the worry of additional overhead. In the end, this translates to huge cost savings since you only pay for the resources that you need, when you need them.

                Use cases of serverless functions

                Serverless technology, like others in cloud computing, is not a one-size-fits-all approach. Consideration should always be given to how it will be utilized and whether it is appropriate for your organization.

                In general, if you’re workload can be described by one of the following, a serverless approach may be for you:

                • Easy to modularize for asynchronous and concurrent work
                • On-demand utilization with potential uncertainty in scaling requirements for resources and infrastructure
                • Stateless, ephemeral, and doesn’t require instantaneous start-up times
                • Business requirements that require fast development and deployment cycles

                More specifically, according to the Cloud Native Computing Foundation (CNCF) whitepaper, the top 10 serverless use cases include: 

                1. Multimedia processing: functions that operate on a file
                  A discrete, parallelizable task that runs infrequently and can scale in response to demand.

                  Examples:

                  • Users upload files, and you can execute the desired process in response to that upload, such as transcoding video for different devices or resizing images.
                  • An application accepts images as input and implements image recognition on it, such as for document verification, search by image, or as a payment method.
                2. Database changes or change data capture: functions that are invoked when data is inserted, modified, or deleted from a database.

                  Tasks that can vary in frequency and complexity.

                  Here, these functions would perform in a fashion like a traditional SQL trigger, except that they can also perform a variety of parallel functions external to the database itself, such as invoking an external service (like sending an email) or updating an additional database.


                  Examples:

                  • Ensuring that any proposed database changes meet acceptable quality thresholds or other requirements.
                  • Automatically translating data to another language after it’s been received.
                3. IoT sensor input messages: functions that respond to messages from network-connected devices

                  Scalable tasks that can protect downstream services from sudden and drastic increases in load.


                  Example:

                  • Efficiently and quickly filter, manage, and respond to MQTT (MQ Telemetry Transport) messages from reporting devices and scale in response.
                4. Stream processing at scale: functions that process data within a potentially unbounded stream of messages 

                  Tasks that require high performance, scalability, and computationally intensive processing, but are part of non-transactional, non-request/response workloads.

                  Here, functions would read and process messages from an event stream. In many cases, this would require that the data be compared against a set of context objects (e.g., in a NoSQL or in-mem DB) or aggregated and stored in an object or a database system.


                  Example:

                5. Chatbots: functions that provide customer engagement and query response while automatically scaling for peak demands 

                  Scalable tasks that don’t suffer from non-zero cold start-up times.

                  People generally expect some delays when engaging in a conversation, so some latency due to processing times or service start-up won’t adversely affect customer perceptions.


                  Example:

                  • Support and sales bots connected to organizational services can provide context-aware responses to product queries, support requests, or other service-related features.
                6. Batch jobs/scheduled tasks: scalable tasks that require intense parallel computation, IO, or network access for only short periods at a time

                  Examples:

                  • A scheduled task such as a nightly backup job (e.g., cron jobs).
                  • Jobs that send large quantities of emails in parallel.
                7. HTTP REST APIs and web apps: functions that perform traditional request and response workloads 

                  Examples:

                  • Applications that provide individual REST calls (GET, POST, UPDATE, and DELETE) can scale independently and be billed separately, even if they share a common data backend.
                  • Online instructional services (tutorials, testing, training, etc.) that run exercise code in an event-driven sandboxed environment and provide user feedback based on comparisons with a set of expected results. Since an instance can be created for each user accessing the site, the system can both scale and charge independently for access.
                8. Mobile back ends: functions that build a REST API backend workload above the Banking as a Service (BaaS) APIs

                  Scalable tasks that provide fast, on-demand service and/or quick development cycles when time-to-market is critical.

                  This use case ties into the core advantages of serverless functions by allowing cloud providers to manage backend tasks while developers focus on providing services that both the customer and organization require.


                  Examples:

                  • Optimizing performance and not worrying about investing in infrastructure expansion/provisioning when a game becomes a viral hit.
                  • Consumer business applications that need quick iterations to find product/market fit, or when time-to-market is critical.
                  • Mobile apps that use event-driven access to BaaS such as purchases or microtransactions.
                  • "Throwaway" or short-term use mobile applications, like a scheduling app for a large conference that may have widely varying usage depending on date and time.
                9. Business logic: functions that coordinate microservice workloads that execute a series of steps in a business process

                  Examples:

                  • A trading desk that handles stock market transactions and processes trade orders and confirmations from a client or based on preconfigured alerts/triggers.
                  • Event requests from client portals are managed by a coordination function and delivered to appropriate serverless functions.
                10. Continuous Integration (CI) pipeline: functions that provide the ability to remove the need for pre-provisioned hosts

                  Example:

                  • Build jobs triggered by a code commit or merged PR. A function call would be invoked to run the build and deploy specifically for this instance.

                Functions as a Service (FaaS)

                Functions as a Service (FaaS) is a cloud services platform that allows customers to rapidly build and deploy serverless functions. FaaS allows developers to write code as self-contained functions executed in response to discrete events like image uploads or in-app events. The beauty and utility of the FaaS model are that it provides significant cost savings since these underlying functions are triggered as ephemeral events, naturally scaling on demand, and only using as many resources as are needed at the time. FaaS platforms are offered by most cloud providers and are increasingly being adopted by developers to reduce complexity and increase the velocity of development. Oracle Functions, AWS Lambda, and Microsoft Azure Functions are some of the FaaS offerings commonly being used by developers to build serverless functions.

                Developer features

                • Developers don’t need to manage any infrastructure
                • Productivity for new and experienced developers
                • Support for various programming languages
                • Built on open standards (Fn Project, OpenWhisk, Docker, CloudEvents)

                Oracle Functions

                Oracle provides you with a robust platform to easily develop and deploy serverless applications through Oracle Cloud Infrastructure (OCI), Oracle Functions service. Oracle Functions is a fully managed, multi-tenant, highly scalable, on-demand, FaaS platform. This means that you can get the services and resources you need when you need them.

                At its core, Oracle Functions are built on enterprise-grade Oracle Cloud Infrastructure and powered by Fn Project, Docker, and CloudEvents. Fn Project is an Apache 2.0 licensed open-source engine. Fn Project is remarkably flexible. It’s a container-native, serverless platform that can be run anywhere, either in the cloud or on-premises. Fn Project allows you to develop and test a function locally, then deploy it directly to Oracle Functions when you’re ready.

                Benefits of Oracle Functions

                Since the architecture that Oracle Functions relies on is both serverless and scalable, it means that there's no infrastructure or software administration for you to worry about. Oracle Functions simply ensures that your app is highly available, scalable, secure, and monitored, leaving you to focus on delivering the best experience possible. Oracle Functions also allows you to develop in virtually any language (Java, Python, Node, Go, Ruby, or C#), letting you choose what’s best for your application. For more advanced use cases, you can even bring your own Dockerfile. And the icing on the cake is that once you deploy your code and then call it either directly or trigger it in response to specific events, you only get billed for the resources you use on execution.

                All these features of Oracle Functions make them an ideal way to enhance the experience of both customers and developers alike. They not only make the deployment of new code quicker and easier to automate, but they also significantly decrease the possibility of downtime during deployment and let your services readily adapt to user demand.

                Getting started with Oracle Functions

                Developing your first function has never been easier. We provide you with multiple paths to the tools you need to get started. You can access Oracle Functions through the Console, CLI, or a REST API. Additionally, you can access the functions you deploy by using the CLI or by making signed HTTP requests.

                We realize that security is more important than ever and Oracle Functions is integrated with OCI Identity and Access Management (IAM), providing easy authentication with native Oracle Cloud Infrastructure identity functionality.

                To get up and running quickly with Oracle Functions, see the Functions QuickStart Guides and the resources listed below.

                Resources

                Latest content

                Explore and discover our latest tutorials

                Serverless functions

                Serverless functions are part of an evolution in cloud computing that has helped free organizations from many of the constraints of managing infrastructure and resources. 

                What is a blockchain?

                In broad terms, a blockchain is an immutable transaction ledger, maintained within a distributed peer-to-peer (p2p) network of nodes. In essence, blockchains serve as a decentralized way to store information.

                OCI CLI

                The CLI is a small-footprint tool that you can use on its own or with the Console to complete Oracle Cloud Infrastructure tasks. The CLI provides the same core functionality as the Console, plus additional commands.