HarperDB is Collapsing the Stack: Introducing Custom Functions
Tags: database, showdev, node, serverless
Published: 2021-09-09 15:35:17

Introducing the newest innovation from HarperDB: [HarperDB Custom Functions](https://harperdb.io/docs/custom-functions/). With the release of HarperDB 3.1 users are able to define their own API endpoints within HarperDB. What does that mean for you? ___HarperDB grows from a distributed database to a distributed application development platform with integrated persistence - one that can serve as a single solution for all of your backend needs___. We’re collapsing the stack!

Alright, alright, what’s the big deal? Up until 3.1, in order to power an application you would need to deploy and host your backend API code on additional servers, then have them call out to HarperDB for database needs. This is a pretty typical software stack, but at HarperDB, we’re far from typical. We’re constantly innovating and changing the game. Custom Functions enable developers to build their entire application backend in one place. Oh yeah, and it’s faster, significantly faster! Traditional architectures naturally introduce latency as data moves across multiple servers through a local network or potentially even the Internet. HarperDB is collapsing the stack onto a single server, which eliminates any and all network latency. This frees up headroom for achieving higher throughput from a single server. Capitalizing on [HarperDB’s already powerful horizontal scalability](https://harperdb.io/blog/reduce-latency-geo-distributed-databases/), this means you can now distribute __both__ your APIs and your database to the edge.

For those familiar with modern cloud architectures, Custom Functions are just like AWS Lambda functions. For those familiar with relational databases, they’re like Stored Procedures. You define your logic and choose when to execute it. At a high level it’s as simple as that! They’re low maintenance and easy to develop. You can develop HarperDB Custom Functions in the Studio or in your own IDE and Version Management System. HarperDB Custom Functions can be maintained like any other development project, in fact, the sample Custom Functions provided in the Studio are generated from our public GitHub repository. That means you can develop, maintain, and deploy your HarperDB Custom Functions code just like any other development project, so you don’t have to deviate from your existing development practices. That’s great news! 

![HarperDB Studio Functions Editor](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6vte11j2ulbpvs7c2x28.png)<figcaption>_HarperDB Studio Functions Editor_

What makes Custom Functions so powerful? They leverage the full power of [Node.js](https://nodejs.org/) and [Fastify](https://www.fastify.io/). HarperDB Custom Functions projects are effectively just Node.js projects, which means you can leverage the npm ecosystem, opening the doors to fast and efficient development. Fastify serves as the basis for the webserver, which means you can define and build a fully functional REST API with all the bells and whistles you’d expect. The key differentiator is that these Fastify routes have direct access to HarperDB core methods, bypassing the HarperDB API, and instead interacting directly with HarperDB on the same machine. 

![WebStorm IDE with HarperDB Functions Project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x279wa5z0ke9ka9hnf27.png)<figcaption>_WebStorm IDE with HarperDB Functions Project_

By collapsing the stack, we deliver unparalleled performance and efficiency out of the box. Let’s take a look at some different ways Custom Functions can be used. I’m not going to cover everything here, in fact, I’m sure there are plenty of options that I haven’t even thought of.


* __Integrate with third-party apps and APIs__: Seamlessly connect third-party/external data with data stored in HarperDB within a single function.
* __Utilize third-party authentication__: Tightly integrate with third-party application providers to validate user requests within your API.
* __Define your own database functionality__: HarperDB is always adding features, but let’s say there’s a feature you need that’s missing. Build a HarperDB Custom Function to solve the problem. For example, if you need to enforce row-level security based on a user account, write a function! 
* __Serve a website__: Custom Functions can serve static content and serve as backend APIs, which means you can fully power a website or web app all with HarperDB.

These are just some of the ideas we’re kicking around with HarperDB Custom Functions. We’ll be hosting a [livestream event next week (September 14th at 6pm MT)](https://harperdb.io/harperdb-custom-functions-event/) where you can watch a live product tour! We look forward to hearing what the HarperDB community can build. Please share any ideas you have in the comments, I’m eager to hear what the community has to say! 

---
Since this will be the initial release of HarperDB Custom Functions, please let us know what else you’d like to see in future releases. You can submit your ideas to our feedback board here: [feedback.harperdb.io](https://feedback.harperdb.io/).