DEV Community

Alex Spinov
Alex Spinov

Posted on

Fauna Has a Free API — Here's How to Build Serverless Apps with Zero Infrastructure

A developer I know was building a multiplayer game. He needed a database that could handle concurrent writes from 1,000 players without conflicts. Traditional databases needed complex locking. Fauna handled it natively with ACID transactions — globally distributed, zero config.

What Fauna Offers for Free

Fauna free tier:

  • 100K read ops and 50K write ops/day
  • 5 GB storage
  • Global distribution — data replicated across multiple regions
  • ACID transactions — multi-document, cross-collection
  • Native GraphQL API
  • Document-relational model — best of both worlds
  • Built-in auth and ABAC

Quick Start

# Install CLI
npm install -g fauna-shell

# Login
fauna cloud-login

# Create a database
fauna create-database myapp
fauna shell myapp
Enter fullscreen mode Exit fullscreen mode

FQL (Fauna Query Language)

// Using the JavaScript driver
const { Client, fql } = require('fauna');

const client = new Client({ secret: process.env.FAUNA_SECRET });

// Create a collection
await client.query(fql`Collection.create({ name: 'users' })`);

// Insert a document
const user = await client.query(fql`
  users.create({
    email: 'alice@example.com',
    name: 'Alice',
    plan: 'free',
    credits: 100
  })
`);

// Query with filter
const activeUsers = await client.query(fql`
  users.where(.plan == 'pro').order(.name)
`);

// ACID transaction — transfer credits between users
await client.query(fql`
  let sender = users.byId('123')
  let receiver = users.byId('456')

  if (sender!.credits >= 50) {
    sender!.update({ credits: sender!.credits - 50 })
    receiver!.update({ credits: receiver!.credits + 50 })
  } else {
    abort('Insufficient credits')
  }
`);
Enter fullscreen mode Exit fullscreen mode

GraphQL API

# Define schema
type User {
  email: String! @unique
  name: String!
  posts: [Post!] @relation
}

type Post {
  title: String!
  content: String!
  author: User!
  published: Boolean!
}

# Query
query {
  allUsers {
    data {
      name
      posts {
        data { title }
      }
    }
  }
}

# Mutation
mutation {
  createPost(data: {
    title: "Fauna is Amazing"
    content: "Here's why..."
    author: { connect: "123" }
    published: true
  }) {
    _id
    title
  }
}
Enter fullscreen mode Exit fullscreen mode

REST API via HTTP

curl -X POST 'https://db.fauna.com/query/1' \
  -H 'Authorization: Bearer YOUR_SECRET' \
  -H 'Content-Type: application/json' \
  -d '{
    "query": "users.where(.plan == \"free\").count()"
  }'
Enter fullscreen mode Exit fullscreen mode

Built-in Auth (ABAC)

// Create a role that limits access
await client.query(fql`
  Role.create({
    name: 'user',
    membership: [{ resource: 'users' }],
    privileges: [{
      resource: 'posts',
      actions: {
        read: true,
        create: '(doc) => doc.author == Query.identity()'
      }
    }]
  })
`);
Enter fullscreen mode Exit fullscreen mode

Perfect For

  • Multi-player apps — ACID transactions prevent conflicts
  • E-commerce — inventory management with strong consistency
  • SaaS platforms — tenant isolation with ABAC
  • Serverless functions — no connection pooling needed
  • Edge computing — globally distributed reads

Need to populate your database with web data? Check out my web scraping actors on Apify — collect structured data from any website.

Need a custom solution? Email me at spinov001@gmail.com — I build data collection pipelines.

Top comments (0)