Overview

Fauna is a true serverless database that combines document flexibility with native relational capabilities, offering auto-scaling, multi-active replication, and HTTPS connectivity.

Key concepts and features

Relational model

Fauna’s data model integrates the best aspects of document and relational databases. Like other document databases, data is stored in JSON-like documents, allowing for the storage of unstructured data and removing the need for an object-relational mapper (ORM) to translate between objects and tables. Fauna also provides key features of relational databases including strong consistency, first-class support for relationships between documents, and the ability to layer on and enforce schema over time.

Documents in Fauna are organized into collections, similar to tables in relational databases, providing a familiar structure for data organization. Collections can specify document types, which define and enforce the structure of documents they contain. This feature allows developers to start with a flexible schema and gradually introduce more structure as their application matures. Importantly, Fauna supports relationships between documents in different collections, enabling complex data modeling without duplicating data. This approach combines the ease of use of document databases with the powerful data modeling capabilities of relational systems.

Distributed architecture

Fauna is built on a distributed architecture that offers global data distribution across multiple regions in a region group. It provides strong consistency for all transactions, even across geographic regions, a feature that sets Fauna apart from many other distributed databases. The system maintains high availability and resilience to regional outages, automatically replicating data and using intelligent routing to provide low-latency access across broad geographies.

API delivery model

As a fully managed service, Fauna eliminates the need for database provisioning, capacity planning, sharding, scaling operations, and routine maintenance. Developers interact with Fauna through a single global API endpoint, greatly simplifying integration and reducing operational complexity. This serverless approach allows development teams to focus on building applications rather than managing infrastructure.

Fauna Query Language

Fauna Query Language (FQL) is a TypeScript-inspired language designed specifically for querying and manipulating data in Fauna. It offers a concise, yet expressive syntax for relational queries, supporting complex joins and data transformations. FQL includes optional static typing to catch errors early in development, improving code quality and reducing runtime issues.

One of FQL’s powerful features is the ability to create user-defined functions (UDFs). These allow developers to encapsulate complex business logic directly within the database, promoting code reuse and maintaining a clear separation of concerns.

Here’s an example of an FQL query:

// 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
}

The query shows how FQL can succinctly express complex operations, including lookups, joins, sorting, and data projection.

Fauna Schema Language

Fauna Schema Language (FSL) allows developers to define and manage database schema as code. It enables version control for schema changes, integration with CI/CD pipelines, and progressive schema enforcement as applications evolve. By treating database schema as code, teams can apply the same rigorous review and testing processes to database changes as they do to application code.

Here’s an example of an FSL schema definition:

collection Customer {
  name: String
  email: String
  address: {
    street: String
    city: String
    state: String
    postalCode: String
    country: String
  }

  compute cart: Order? = (customer => Order.byCustomerAndStatus(customer, 'cart').first())

  // Use a computed field to get the Set of Orders for a customer.
  compute orders: Set<Order> = ( customer => Order.byCustomer(customer))

  // Use a unique constraint to ensure no two customers have the same email.
  unique [.email]

  index byEmail {
    terms [.email]
  }
}

This schema defines a Customer collection with specific fields, a computed field, a uniqueness constraint, and an index. The *: Any wildcard constraint allows for arbitrary ad hoc fields, providing flexibility while still enforcing structure where needed.

Transactions and consistency

In Fauna, every query is a transaction, ensuring ACID compliance across all operations, even in globally distributed Region Groups. Fauna’s distributed transaction engine, based on the Calvin protocol, provides strict serializability for all read-write queries and serializable isolation for read-only queries. This guarantees real-time consistency across all replicas without relying on clock synchronization, eliminating anomalies common in systems dependent on synchronized clocks.

Fauna’s strong consistency model has been verified by Jepsen, an independent third-party analysis firm, confirming its ability to maintain high levels of consistency even under various failure scenarios. Despite these robust guarantees, Fauna maintains high performance and low latency, even for geographically distributed deployments, thanks to its innovative architecture that separates transaction ordering from execution.

Security and access control

Fauna provides comprehensive security features to protect your data and control access. It offers role-based access control (RBAC) for coarse-grained permissions and attribute-based access control (ABAC) for fine-grained, dynamic access rules. This combination allows for highly flexible and precise control over who can access and modify data.

The system includes built-in user authentication and also supports integration with third-party identity providers, allowing you to use existing authentication systems. All data in Fauna is encrypted at rest and in transit, ensuring protection at all times.

Change data capture (CDC) and real-time events

Fauna’s Change data capture (CDC) feature enables real-time application features. Developers can subscribe to changes in collections or specific documents, receiving either atomic push updates using real-time Event Streams or on-demand batch pull updates using Event Feeds . Events are particularly useful for maintaining live application states, building collaborative features that require real-time synchronization, and mirroring changes into external systems.

Database model

Fauna’s database model makes it easy to create databases for isolated environments, such as staging and production, and build secure multi-tenant applications.

For multi-tenant applications, developers can create isolated child databases for each tenant, applying separate access controls and schema as needed.

The same approach can be applied to isolated environments, enabling separate databases for each environment, ensuring that changes in one environment do not affect others.

This model simplifies administration, ensures clear separation between environments, and guarantees that tenants or environments cannot interfere with each other’s data.

Deployment options

Fauna offers public Region Groups that span multiple geographic areas such as the US or the EU, allowing compliance with data residency requirements and optimization for low-latency access across specific regions.

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.

Developer experience

Fauna is designed to integrate seamlessly into modern development workflows. It provides official client drivers for popular programming languages such as JavaScript, Python, Go, Java, and C#. The Fauna CLI offers tools for schema management and database operations, while the Dashboard enables visual database management and query execution. Additionally, the Fauna container image can be used for local testing and validation, even in environments where connectivity is limited.

By supporting schema-as-code practices and CI/CD integration, Fauna allows development teams to treat database changes with the same rigor as application code changes. This approach promotes better collaboration, easier testing, and more reliable deployments.

Comparison to other databases

While Fauna shares some characteristics with both document and relational databases, it offers unique capabilities that set it apart.

Document databases (Example: MongoDB)

Fauna and MongoDB are both document databases, but Fauna offers a unique combination of document flexibility with relational database features. While MongoDB provides a flexible document model and horizontal scalability, Fauna enhances this with strong consistency guarantees, built-in support for complex relationships, and more powerful querying capabilities through FQL. Fauna’s document model allows for enforcing schema when needed, supporting complex joins, and maintaining ACID compliance across distributed environments. Unlike MongoDB, Fauna provides native multi-region distribution and doesn’t require separate replication setup or sharding configurations.

See Fauna for MongoDB users

Key-value stores (Example: DynamoDB)

Compared to key-value stores like DynamoDB, Fauna offers a richer data model and query capabilities while maintaining high performance and scalability. Fauna’s document model allows for more complex data structures and relationships, reducing the need for denormalization often required in DynamoDB. Fauna provides native support for secondary indexes without the limitations found in DynamoDB, such as the ability to index nested fields and arrays. Additionally, Fauna’s query language (FQL) allows for more sophisticated queries and data manipulations within the database, potentially reducing application-side complexity. Both databases offer serverless operations, but Fauna’s multi-region distribution is built-in, simplifying global deployment.

Traditional relational databases (Example: PostgreSQL)

While both Fauna and PostgreSQL are relational databases supporting ACID transactions, their architectures and deployment models differ significantly. PostgreSQL follows a traditional client-server model with a fixed schema, while Fauna offers a flexible document model with optional schema enforcement. Fauna’s serverless, globally distributed architecture contrasts with PostgreSQL’s typical single-region deployment, offering easier scalability and global distribution out of the box. Fauna’s FQL provides a modern, programmable query interface, whereas PostgreSQL uses standard SQL. Both support stored procedures, but Fauna’s User-Defined Functions (UDFs) are written in FQL and executed within the database’s distributed environment. Fauna also offers built-in temporality and multi-tenancy features, which typically require additional setup in PostgreSQL.

See Fauna for SQL users

NewSQL databases (Example: CockroachDB)

Fauna and NewSQL databases like CockroachDB both aim to combine the scalability of NoSQL systems with the strong consistency of traditional relational databases. However, Fauna’s approach differs in its serverless, API-first design. While CockroachDB focuses on providing a distributed SQL database, Fauna offers a relational document model with its own query language (FQL). Fauna’s built-in multi-tenancy and attribute-based access control provide more granular security options out of the box. Both databases offer global distribution, but Fauna’s serverless nature means users don’t need to manage nodes or worry about data placement strategies. Fauna’s temporal query capabilities and Event Feeds and Event Streams are also notable features not typically found in NewSQL offerings.

Summary

With this combined set of features, Fauna aims to provide a unified solution that meets the diverse needs of modern application development, from rapid prototyping to global-scale production deployments. Its unique approach allows developers to build sophisticated, globally distributed applications without the operational complexity traditionally associated with such systems.

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!