Fauna best practices

Do we have a “Best Practices” document for Fauna?

What I’m specifically looking for are the following…

  1. How to optimize queries for performance.
  2. How to optimize queries for cost.
  3. Security
  4. Database modeling.
  5. Indexing best practices.
  6. Anti-patterns

We realise there is a need to have such a document and are currently in the process of writing a guide including example code and an example app that answers all of these questions. The application that will also serve as a base was announced in this article and also gives a sneak preview on:

  • How to model in FaunaDB

  • How to structure your queries

  • The authentication features and how to bootstrap your app.

  • When to use User Defined Functions.

We intend to go further and write one guide that will walk you through the rest of the things you mention. Currently, we are writing on best practices for authentication.

In the meantime, some external writers are doing a great job on writing unofficial guides, for example there is this one on modelling which takes a Primary Key approach. Shortly there will be a full series on how to get started with FQL.

Your input is greatly appreciated, we’ll keep the topics you mentioned into account while we continue on the guide. And I hope to edit this answer shortly with resources that answer each of your topics :slight_smile:

To anyone that passes by and is looking for something similar, feel free to add topics to the list of 6 items that were mentioned already.


I’d love to read an in-depth article about those two points.

For performance my first hunch has been to think in relational terms. The more documents a query “touches”, the slower it will be. So to get better perf use as less documents as possible for a given query. I don’t know if this is the correct way of thinking about it or not.

As far as cost, I understand that any index and document read generates an operation but I still don’t quite get how that applies for many use cases. For example, what happens if we use Map/Lambda/Get on the results of an index? Do we pay for the index read and then for each Get? And what if we use Filter on a list of documents? Etc.

Do we pay for the index read and then for each Get?

Yes. “getting” a Set costs a Read Op, e.g. using Paginate. Every execution of Get also costs a Read Op.

Docs have more specifics, though they don’t include a lot of details. https://docs.fauna.com/fauna/current/concepts/billing.html#read

There’s a good discussion here in the forums.