Fauna tour
Fauna is a true serverless database that combines document flexibility with native relational capabilities, offering auto-scaling, multi-active replication, and HTTPS connectivity.
This tour guides you through the process of building a basic JavaScript app with Fauna, highlighting Fauna’s unique features and developer experience.
Prefer to learn using a sample application? Check out the driver sample apps on GitHub: |
Distributed, serverless architecture
Fauna databases are easy to set up and fully managed — no provisioning, capacity planning, or operational overhead required.
Your database’s data is automatically replicated across regions in its region group, ensuring high availability and resilience to outages.
Virtual Private Fauna (VPF)
For enhanced security and customization, Fauna offers Virtual Private Fauna (VPF). This option provides single-tenant deployments on dedicated infrastructure with a customizable regional footprint across multiple cloud providers.
VPF is designed to meet specific security and compliance requirements for organizations with more stringent needs.
API delivery model
In Fauna, every query is a transaction, ensuring ACID compliance across all operations, even in globally distributed Region Groups.
Fauna uses stateless, token-based authentication. Each query is an independently authenticated request to the global Query HTTP API endpoint.
Fauna routes and authorizes queries using an authentication secret, scoped to a specific database. Fauna uses replicas and intelligent routing to ensure queries have low latency.
Client drivers
To run queries, your app can work directly with the Fauna Core HTTP API or use a Fauna client driver for your preferred programming language:
Each driver is a lightweight, open-source wrapper for the HTTP API. They’re maintained by Fauna and lightweight enough for use in serverless functions, edge networks, or other resource-constrained environments.
Fauna Query Language
You use Fauna Query Language (FQL) queries to read and write data in a Fauna database.
Fauna stores data as JSON-like documents, organized into collections. Queries can filter and fetch documents from a collection as a set, and iterate through each document.
Static typing
FQL is a TypeScript-inspired language and includes optional static typing. You can use typing to catch errors early in development, improving code quality and reducing runtime issues.
Relational queries
FQL also offers a concise, expressive syntax for relational queries, supporting complex joins and data transformations:
// Gets the first customer with
// an email of "alice.appleseed@example.com".
let customer: Any = Customer
.where(.email == "alice.appleseed@example.com")
.first()
// Gets the first order, sorted by descending creation time,
// for the customer.
let order: Any = Order
.where(.customer == customer)
.order(desc(.createdAt))
.first()
// Project fields from the order.
// The order contains fields with document references.
// Projecting the fields traverses references,
// similar to a SQL join.
order {
// `Customer` document reference
customer {
name,
email
},
status,
createdAt,
items {
// Nested `Product` document reference
product {
name,
price,
stock,
// `Category` document reference
category {
name
}
},
quantity
},
total
}
User-defined functions (UDFs)
You can save and reuse FQL statements as user-defined functions (UDFs), which works similarly to stored procedures in SQL. UDFs let you encapsulate and store business logic in your database, promoting code reuse and maintaining a clear separation of concerns.
Schema as code
Fauna Schema Language (FSL) lets you define and
manage database schema as code. You can manage your database’s FSL schema
using the Dashboard or as .fsl
files using the Fauna
CLI.
Using the CLI lets you:
-
Store
.fsl
schema files alongside your application code -
Pull and push schema to your Fauna database from a local directory
-
Place database schema under version control
-
Deploy schema with CI/CD pipelines
-
Change your production schema as your app evolves using progressive schema enforcement and zero-downtime migrations
Change data capture (CDC) and real-time events
Fauna event sources let you build change data capture (CDC) and real-time app features for your app.
An event source tracks changes to a specific Set of documents or document fields, defined by an FQL query. The event source emits an event whenever a tracked change occurs.
An app can consume an event source in two ways:
Event Feeds : Asynchronous requests that poll the event source for paginated events.
Event Streams: Real-time subscriptions that push events from the event source to your application using an open connection to Fauna.
Security and access control
Fauna supports both role-based access control (RBAC) for coarse-grained permissions and attribute-based access control (ABAC) for fine-grained, dynamic access rules.
Built-in user authentication
Fauna includes a built-in end-user authentication system called tokens.
Each token is associated with an identity document representing an end user, system, or other identity. A credential associates an end user’s password with the identity document.
With ABAC, you can use FQL predicates to dynamically grant roles and privileges based on the attributes of identity documents, the query, and other context.
Database model and multi-tenancy
Fauna’s database model makes it easy to create databases for isolated environments, such as staging and production, and multi-tenant applications:
-
Each Fauna database can have many child databases. You can use child databases as tenants for your application.
-
All databases, including child databases, are instantly allocated without provisioning or warmup.
-
Each database is logically isolated from its peers with separate access controls.
-
All Fauna resources, excluding top-level keys, exist as documents within a specific database. This includes collections, user-defined functions, and child databases.
-
Queries run in the context of a single database and can’t access data outside the database. Databases aren’t aware of their parents or peers.
You can populate and access the database’s data using a secret that’s scoped to the database.
You can use a scoped key to manage a child database’s data from its parent database.
Next steps
Congratulations — You’ve completed the tour! 🏆
This introduction is just the tip of the iceberg. There’s much more of Fauna to explore. To help you on your journey, we’ve curated a selection of resources below.
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!