🚀 Fauna Architectural Overview White Paper: Learn how Fauna's database engine scales with zero ops required
Download free ->
Fauna logo
FeaturesPricing
Learn
Customers
Company
Support
Log InContact usStart for free
Fauna logo
FeaturesPricing
Customers
Start for free
© 2024 Fauna, Inc. All Rights Reserved.
<- Back
Schema launch blog header 5

Announcing Fauna Schema: Build, Iterate, and Evolve Schema with Zero Downtime

Wyatt Wenzel & Bryan Reinero |Jun 20th, 2024|

Categories:

SchemaDevOpsRelationalDocumentFeaturesNews

We are excited to announce Fauna Schema, a comprehensive suite of tools that enables development teams to define, manage, progressively type, enforce, and evolve their database schema to meet changing business needs. Today we are adding document types and zero downtime migrations – rounding out Fauna Schema, which is comprised of three core elements:

Combing the powers of document and relational schema approaches

The need to evolve schema on production applications as business requirements change is a significant challenge for both relational and document databases.

In traditional relational databases, the definition of a table's columns and their data types is integral not only to the table's structure but also to its physical layout on disk. This rigid structure ensures that data always conforms to the expected format, providing consistency and reliability. However, altering the table's definition as your application evolves often necessitates migrating existing rows to fit the new schema, which can be problematic at scale. This inflexibility, combined with the lack of support for live schema migrations and gradual typing, makes it challenging to change the schema as the dataset grows, reducing developer productivity and increasing costs and complexity.

On the other hand, document databases, while offering more flexibility with their schema, often lack stringent schema enforcement. Their approach to schema validation is generally more relaxed, optionally applying what is at best a limited write-time validation while remaining fundamentally schemaless under the hood. This means that when a schema definition is changed, existing documents are usually left unchanged, leading to inconsistencies and less reliable data integrity over time. Document databases often have bolted-on and rudimentary schema capabilities, support only a single type per field, and lack type checking when composing queries, which increases the risk of conflicts and runtime errors.

Fauna Schema now uniquely delivers the structure, enforcement, and reliability of schema of traditional relational databases, with the flexibility of a modern document model – reinforcing Fauna’s investment in delivering a true document-relational database that increases development velocity and decreases risk.

“Fauna's new Schema capabilities unlock powerful optionality for evolving and enforcing our database schema over time,” shared Cameron Bell, Head of Software, Systems, & Data at Connexin. “These features will enable us to dial-in and dial-out schema as our applications evolve and adapt to changing business requirements without compromising data integrity or business operations.”

Define and manage schema alongside application code

With Fauna Schema Language (FSL), developers can define their domain models, access controls, and business logic in a human-readable language, contained in a set of files that can be managed alongside their related application code. FSL enables developers to treat their database schema just like they do their application code. Leveraging GitHub, they can automate testing that is triggered by pushing a new schema version alongside their application code to ensure the integrity of the database.

Combined, these features enable database development to match the pace of application development by incorporating database schema-level changes into broader CI/CD workflows – a crucial advancement for enterprise engineering teams tasked with building, scaling, and improving applications at every stage of development.

Progressively type and enforce schema

Document types enable you to define and enforce schema structures directly within the database. The data type of a collection's documents takes its name from its collection. For example, document types in the Customer collection have a type of ‘Customer’. You define a document type in a collection schema using field definitions and wildcard constraints.

  • Field definitions: Field definitions represent predefined fields for a collection’s documents. These definitions consist of the field name, accepted data types, and default values. By incorporating field definitions into the collection schema's document type, you ensure that each document conforms to a predefined structure.
  • Wildcard Constraint: A wildcard constraint allows ad hoc fields within documents and controls accepted data types for these fields. This flexibility enables developers to introduce new field definitions and degrees of enforcement dynamically. Users can define where in the spectrum of permissive to strict they need their schema to be.

Document types complement Fauna’s previously released computed fields and check constraints, together delivering the structure and reliability of traditional relational databases with the flexibility of a modern document model.

Computed fields allow the values of fields in documents to be dynamically generated based on expressions defined by the user. This means developers can create fields whose values are calculated at the time of query, enabling dynamic composition of objects and field values. These fields can be indexed, providing even greater flexibility in query patterns so developers can accurately define their true data model in the database, unlike other databases which require them to be defined in mapping layers running outside of the database.

By defining rules within your schema, check constraints ensure that data written to the database adheres to specific business logic, such as ensuring a bank account balance never falls below zero or a user's age falls within a reasonable range. This feature is especially valuable for applications that require strict data validation to maintain data integrity and enforce business rules directly at the data layer.

Development teams are able to encode dynamic, cross-collection relationships in the collection definition as an element of their schema design, so they can generate data and object models in real-time to avoid the performance disadvantages inherent in a denormalization strategy required in other document databases.

Evolve schema with zero downtime migrations

The introduction of zero downtime migrations empowers teams to implement schema changes without service interruptions, facilitating continuous deployment and integration practices. Whenever a collection definition changes, Fauna will migrate every existing document in the collection to conform to the new definition. Driven via FSL, these migrations can be versioned as code, and allow developers to script database schema changes directly into their application's CI/CD pipelines.

Zero downtime migrations significantly enhance operational efficiency by eliminating the need for maintenance windows or downtime typically associated with schema changes, thus maintaining uninterrupted user experience and service delivery. By integrating schema management into the CI/CD pipeline, teams can achieve a more streamlined and automated deployment process, reducing the risk of human error and accelerating development cycles. Additionally, the ability to version migrations as code ensures traceability and reproducibility, which are essential for debugging and auditing changes.

Enhancing the application development lifecycle with Fauna Schema

With the introduction of document types and zero downtime migrations, Fauna continues to add capabilities traditionally associated with relational databases to its document model, while innovating to meet the needs of today’s modern applications and agile software development practices.

“Document databases have proven the many benefits of a developer-friendly and flexible document model but are missing many of the key functionalities native to relational databases, including powerful relational query capabilities, ACID compliance, and schema enforcement,” said Hassen, VP Product of Fauna. “With the addition of our new schema capabilities, development teams can move faster with confidence by defining and managing their schema alongside application code, and progressively enforce schema structure over time as needed.”

If you enjoyed our blog, and want to work on systems and challenges related to globally distributed systems, and serverless databases, Fauna is hiring!

Share this post

TwitterLinkedIn

Subscribe to Fauna's newsletter

Get latest blog posts, development tips & tricks, and latest learning material delivered right to your inbox.

<- Back