UDFs vs functions via driver?

As the title says, are there any benefits of using one over the other? Is it good practice to use only one type or is using both at the same time standard practice?

TL;DR - prefer UDFs.

In general, I recommend a “UDF-only” approach where all of your business logic is encapsulated in UDFs and your client-side code doesn’t use any FQL except for Call().

This encapsulation has several benefits:

  • your server doesn’t have to “trust” that your client is doing the right thing
  • you can make changes to your business logic without modifying/redeploying clients
  • you can consume your UDFs across multiple platforms/drivers, including as GraphQL resolvers
  • you can do ABAC inside your UDFs
  • you can compose UDFs from other UDFs

I’ll always leave room for use cases I haven’t considered/built with, but I have not yet found a situation where I felt that putting the FQL calls in the client code instead of in a UDF was the right approach.

2 Likes

Rob puts his money where his mouth is with extensive use of UDFs, live on Twitch!

:+1: to UDF’s everywhere.

To clarify, I prefer defining UDF’s in code and using that code in a bootstrapping script, which is commited to source control. Bootstrap code is separate from client code, where the client is effectively limited to uses of Call.

2 Likes

Thanks @ptpaterson and @rob for your insights! I’ve mostly been following the UDF only approach but now that the codebase has grown quite large, I feel like the list of UDFs is getting quite cluttered in the dashboard, which may just be my personal OCD speaking. So I’ve been trying to find ways to lessen the number of functions I have to define or put that logic somewhere else I can’t easily see like a JavaScript function on the client lol

I’d echo @ptpaterson 's suggestion of defining your UDFs separately from the consuming client code.

Two suggested approaches are to use our plugin for the Serverless Framework or our Fauna Schema Migrate tool, as both allow you to define each UDF in a separate file. If there’s another IaC tool you’d like to see support for - let us know!

1 Like