DEV Community

Otto
Otto

Posted on

PocketBase: The Open-Source Firebase Alternative You Can Self-Host in 5 Minutes

PocketBase: The Open-Source Firebase Alternative You Can Self-Host in 5 Minutes

If you've ever been frustrated by Firebase's pricing at scale or wanted full control over your backend data, PocketBase is the answer. One binary. No Docker required. Runs anywhere.

What is PocketBase?

PocketBase is an open-source backend in a single file — built with Go. It gives you:

  • Real-time database (SQLite under the hood)
  • Authentication (email/password, OAuth2, anonymous)
  • File storage with built-in image resizing
  • Admin dashboard out of the box
  • REST + Realtime API auto-generated from your schema
  • JavaScript and Go SDK

And the best part: the entire backend is ~30MB, runs on a $5 VPS, and can handle thousands of users.

Getting Started in 5 Minutes

Step 1: Download & Run

# Linux/Mac
curl -L https://github.com/pocketbase/pocketbase/releases/latest/download/pocketbase_linux_amd64.zip -o pb.zip
unzip pb.zip
./pocketbase serve

# That's it. Admin UI at: http://127.0.0.1:8090/_/
Enter fullscreen mode Exit fullscreen mode

Step 2: Create Your First Collection

In the admin UI, create a "posts" collection with fields:

  • title (text, required)
  • content (editor)
  • author (relation → users)
  • published (bool)

Step 3: Connect Your Frontend

import PocketBase from 'pocketbase';

const pb = new PocketBase('http://127.0.0.1:8090');

// Authentication
const auth = await pb.collection('users').authWithPassword(
  'user@example.com',
  'password123'
);

// Create a post
const post = await pb.collection('posts').create({
  title: 'My First Post',
  content: 'Hello from PocketBase!',
  author: auth.record.id,
  published: true
});

// Fetch posts with real-time updates
pb.collection('posts').subscribe('*', function (e) {
  console.log('Change type:', e.action); // create, update, delete
  console.log('Record:', e.record);
});

// Query with filters
const records = await pb.collection('posts').getList(1, 20, {
  filter: 'published = true',
  sort: '-created',
  expand: 'author'
});

console.log(records.items);
Enter fullscreen mode Exit fullscreen mode

Real-World Example: Building a Blog API

// Full CRUD for a blog with auth
class BlogAPI {
  constructor(baseUrl) {
    this.pb = new PocketBase(baseUrl);
  }

  async login(email, password) {
    return await this.pb.collection('users').authWithPassword(email, password);
  }

  async createPost(title, content) {
    if (!this.pb.authStore.isValid) {
      throw new Error('Not authenticated');
    }

    return await this.pb.collection('posts').create({
      title,
      content,
      author: this.pb.authStore.model.id,
      published: false
    });
  }

  async publishPost(postId) {
    return await this.pb.collection('posts').update(postId, {
      published: true
    });
  }

  async getPosts(page = 1) {
    return await this.pb.collection('posts').getList(page, 10, {
      filter: 'published = true',
      sort: '-created',
      expand: 'author'
    });
  }

  subscribeToNewPosts(callback) {
    this.pb.collection('posts').subscribe('*', (event) => {
      if (event.action === 'create') callback(event.record);
    });
  }
}

// Usage
const blog = new BlogAPI('http://localhost:8090');
await blog.login('author@blog.com', 'secure_pass');
const post = await blog.createPost('Hello World', 'My first post!');
await blog.publishPost(post.id);
Enter fullscreen mode Exit fullscreen mode

PocketBase vs Firebase: Honest Comparison

Feature PocketBase Firebase
Pricing Free (self-host) Free tier → $$$
Data ownership ✅ 100% yours ❌ Google's servers
Setup time 5 minutes 15 minutes
Real-time ✅ SSE ✅ WebSocket
File storage ✅ Built-in ✅ Separate service
Vendor lock-in ✅ None ❌ High
Scale (users) ~10K on small VPS Unlimited ($$)
Auth providers 8 OAuth2 options 10+

Deployment on a $5 VPS

# systemd service for production
sudo nano /etc/systemd/system/pocketbase.service
Enter fullscreen mode Exit fullscreen mode
[Unit]
Description=PocketBase
After=network.target

[Service]
Type=simple
User=pocketbase
WorkingDirectory=/home/pocketbase
ExecStart=/home/pocketbase/pocketbase serve --http=0.0.0.0:8090
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode
sudo systemctl enable pocketbase
sudo systemctl start pocketbase
Enter fullscreen mode Exit fullscreen mode

Add nginx as a reverse proxy with SSL (Let's Encrypt) and you have a production backend for <€5/month.

When to Use PocketBase

Great for:

  • Side projects and MVPs
  • Apps with < 100K users
  • When you need data ownership
  • Replacing Supabase/Firebase for small teams
  • Internal tools

Not ideal for:

  • Massive scale (millions of concurrent users)
  • Complex multi-region deployments
  • When you don't want to manage infrastructure

Manage Your Freelance Projects Better

Building side projects means managing clients, deadlines, and invoices. I keep everything organized in a Notion workspace that handles my entire freelance operation.

Freelancer OS Notion Template — CRM, project tracker, finance dashboard, all in one (€19)


PocketBase is genuinely one of the most exciting tools in the solo developer ecosystem right now. Give it a try — you'll be amazed at what you can build.

What are you building with PocketBase? Share below! 🚀

Top comments (0)