OTF Blog

SERVERLESS FUNCTIONS: WHAT YOUR AGENCY NEEDS TO KNOW

Written by On The Fuze | Dec 3, 2021 8:46:00 PM

Serverless functions provide a way to write server-side code that interacts with HubSpot and third-party services through APIs.

How is that valuable to your agency?

Here’s what your agency needs to know about serverless functions...

What are serverless functions?


Serverless functions are a single-purpose, programmatic feature of serverless computing — also simply called "serverless" — a cloud computing execution model where the cloud provider provisions computing resources on demand for its customers and manages all architectures, including cloud infrastructure. Yet despite its name, serverless computing still relies on cloud and physical servers to execute code, the difference being that it abstracts away the servers, operating systems, and other infrastructure from developers.

The use of serverless functions offers several significant benefits. It frees developers to focus on application development and better-quality application code, as infrastructure concerns, such as redundant code deployments and autoscaling, are handled by the serverless provider. The organization also saves money by only paying for the computing resources it uses instead of overprovisioning physical hardware or renting cloud instances that go unused.

Serverless functions in regard to HubSpot


The launch of CMS Hub introduced serverless functions, themes, and HubSpot default themes. Creating serverless functions and themes previously required using the CMS CLI. You can now do this through the Design Manager.

Default Themes and Modules

HubSpot provides a set of default themes and modules that you can use either as-is or clone and edit. These assets are stored within the read-only @hubspot folder. This folder is accessible both in the Design Manager's Finder and through the CLI using fetch.

To clone themes, modules, and files from that folder to another directory in the Design Manager, right-click the asset in the finder and select clone. This is equivalent to using the CMS CLI to fetch the assets and upload them to a location outside of the HubSpot folder. Once you've done that, the clone will be available to choose from for page creation/editing.

Serverless Function Folders

HubSpot Serverless functions live inside a functions folder. This folder can be named anything but must contain the suffix functions. This is similar to what you see with modules when using the local development tools to edit. They are "module label. module".

Within the functions folder, you will include your .js files, which will contain your functions and your serverless.json file. You might consider adding a README markdown file to communicate what the functions are for, how they work, and if you have a build process to author them.

Importance of serverless functions


Here are the benefits of serverless functions to share with your team and clients...

Infrastructure that Supports Your Apps


Improved Performance of Your Applications 

Serverless functions add another layer of modularity. With serverless functions, you can develop any new functionality or security patch as a completely isolated, single-purpose piece of code. All you have to do is upload your code and tell the platform how to provision it.

Serverless functions not only make the deployment of new code quicker, simpler, and easy to automate — they also significantly decrease the possibility of downtime during a deployment. In short, serverless functions improve the performance of your application and the experience of your developers and customers.

A System that Scales with You

Buying and managing servers aren't always the most sensible choice -- especially if the activity and traffic on your site fluctuate. Managing the capacity of your systems is difficult, and ultimately prevents you from focusing on the customer experience. Serverless functions in CMS Hub remove the stress that scaling your systems can cause. 

Importance of serverless functions


Here are some common use cases for serverless functions...

Common Uses of Serverless Functions

Multi-Language Applications

When building an application, the first discussion is usually about which language to use. The language chosen isn't always about what suits the project best, but rather which resources are already on-hand. With serverless functions, applications can be multilingual.

This fosters polyglot teams and enables seamless integration of services into an application that is written by specialized teams. It further prevents teams from getting locked into using the same language as their legacy software indefinitely; new languages can be used for new services and still talk to legacy services as needed.

API Business Logic for Interacting with a Database

When working with a database, you will often have the business logic for the database operations living in service somewhere on a server. Serverless functions offer a perfect use case for offloading the infrastructure and enabling you to quickly get your API off the ground. You will also often have private variables that you don't want to be exposed to the client. Using a serverless function, you can easily set these and have them securely available for database access as environment variables.

Combining this with a web server like serverless express allows you an easy way to get up and running with a real scalable, enterprise-ready stack that will give you the foundation for most applications.

Looking for experts to help with serverless functions?

At On The Fuze, our clients have access to a delivery team of over 50 full-time HubSpot, Website Development, Design, and QA experts to help their clients with Serverless Functions and many more projects.

If you're a HubSpot Partner who wants to scale without the strain and risks of hiring, training and retaining more employees, contact us to see if OTF is a fit for your agency.