Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Guide to Implementing Function-as-a-Service: A Deep Dive into Serverless Computing

Posted on Oct 12 Serverless computing is gaining more popularity nowadays, especially for launching new applications faster. Serverless does mean that you will not have a server but it is when the server is managed by a third-party application. Developers just need to write code without worrying about the underlying servers or hardware.This serverless can be achieved with various methods one of those is FasS i.e, Function as a Service. You just write code as a function which gets deployed on the cloud. Whenever you need to execute it you just need to fire the function. We will discuss more in the article.Implementing FasS architecture can be challenging when not knowing the principle. So, today we are going to look into implementing function as a service through the following topics:Let’s get started.FasS stands for function as a service, it is a cloud computing model that allows developers to deploy a piece of code as a function to the cloud without managing the underlying technology. This function can be triggered using HTTP requests, database changes, or file uploads. By doing this, it provides the functionality of serverless as it is managed by the platforms. It is one such reason of FasS getting more recognition nowadays.It is particularly popular for building microservices, APIs, and event-driven applications, offering a scalable and cost-effective approach to cloud computing. It can be also used for the rapid development of a prototype or quick application that does not require a lot of functionality. It provides agility to the development cycle. You can also skip a lot of work of setting up of backend and integrating with the frontend. There are a few principles that you should follow while implementing FasS architecture. Here are those:Let’s look into some of the benefits that you can get by using FasS:You can implement functions on cloud platforms such as AWS using lambda function, Azure using Azure Functions, or Google Cloud Platform using Google Cloud Functions. These platforms are good when you use them directly these platforms in your application. But if you don’t use these platforms then it might get tricky to integrate and set the cloud for your application. Apart from directly using the cloud services we can use applications that take away the headache of managing the cloud and we can use functions we ease. One such platform is Supabase. It is a powerful backend-as-a-service platform that allows developers to easily build scalable web applications with serverless functions and a PostgreSQL database.It provides the facility of serverless function through a feature called edge function. The edge here means that it is globally distributed across various edges (cloud servers). So when the request is made to the function, the nearest deployed function will run and send the response. Let’s look into implementing function as a service using supabase. First, let’s set up our project on the supabase dashboard. Visit supabase.com then click on Start your project from the right of the nav bar. This will take you to the sign-in page. Enter your details for sign-in or sign-up as you required. After logging in, you will be redirected to the project page. From here, click on New project to create a project. On the Create New Project page, you will be asked to enter details of your project.Fill in the details of your project. Enter the project’s name as per your choice. For passwords, you can use the Generate a password for generating the password. Select the region that is nearest to the user of your project. In the free tier, you can create two projects. After filling in the details, click on Create new project. It will take a few minutes to set up the project. We need to have supabase CLI to create, and deploy functions to the Supabase. It’s quite easy to install run the below command to install:Note: Node and NPM should be pre-installed to run the command.Now, we need to log in to the subbase in the CLI. To run any supabase command just prefix it with npx supabase then command. So for login here it is:This will ask for the access token. You can generate an access token from here for your project. Enter that token in the asked input.Now, let's go to the project directory where you want to write code for your function. In the root directory, run the below command to initialize the supabase.After this at last we just need to provide the reference URL of your project from supabase. Here is the command for it:Change the to your project reference. You can get the project reference URL from the Supabase's setting→ API. For writing the function, first, we need to create a file for writing the function. You can create the function with the Supabase CLI. Here are the commands:This will create a file in the supabase→function→hello-world with the index.ts. You can write your function here. The index file initially will look like this:It is just like any route file of the backend where you can get the request and send the response to the client. You can access all the API keys such as a Supaabse URL, and Anon key directly using the demo function. This can help in performing other functionality of the supabase. You can write as you will write any other file. For now, we are keeping the same. After writing the function it’s time to deploy the function.Run the below command to deploy the function to the supabase:You can invoke the edge function with the following method:This can be useful in making requests from Postman or any API testing platform to test the function.The below code can be used to invoke the function from any file.We learned about the Function as a Service(FaaS) that can help in the rapid development of the project. Later we see the principle and benefits of using it. After that, we go through a guide on implementing the edge function of Supabase for implementing FaaS in the application.The function does provide lots of flexibility to the developers as they do not have to focus more on architecture and can work on the core functionality of the application. I would love it if you would try to implement a function in your next and then see if it works for you.I hope this article has helped you know the Function as a Service. Thanks for reading the article.Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse marcuskohlberg - Oct 10 Comficker - Oct 6 Sarthak Sharma - Oct 8 Randall - Oct 9 Once suspended, documatic will not be able to comment or publish posts until their suspension is removed. Once unsuspended, documatic will be able to comment and publish posts again. Once unpublished, all posts by documatic will become hidden and only accessible to themselves. If documatic is not suspended, they can still re-publish their posts from their dashboard. Note: Once unpublished, this post will become invisible to the public and only accessible to Suraj Vishwakarma. They can still re-publish the post if they are not suspended. Thanks for keeping DEV Community safe. Here is what you can do to flag documatic: documatic consistently posts content that violates DEV Community's code of conduct because it is harassing, offensive or spammy. Unflagging documatic will restore default visibility to their posts. DEV Community — A constructive and inclusive social network for software developers. With you every step of your journey. Built on Forem — the open source software that powers DEV and other inclusive communities.Made with love and Ruby on Rails. DEV Community © 2016 - 2023. We're a place where coders share, stay up-to-date and grow their careers.



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Guide to Implementing Function-as-a-Service: A Deep Dive into Serverless Computing

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×