DEV Community

Alex Spinov
Alex Spinov

Posted on

Convex Has a Free Reactive Backend — Real-Time Database with TypeScript Functions and Zero Infra

Why Convex?

Convex is a reactive backend that auto-syncs data to your frontend. Change a database record and every connected client updates instantly — no WebSocket code, no polling.

npm create convex@latest
Enter fullscreen mode Exit fullscreen mode

Define Your Schema

// convex/schema.ts
import { defineSchema, defineTable } from 'convex/server'
import { v } from 'convex/values'

export default defineSchema({
  messages: defineTable({
    text: v.string(),
    author: v.string(),
    timestamp: v.number(),
  }),
})
Enter fullscreen mode Exit fullscreen mode

Server Functions

// convex/messages.ts
import { query, mutation } from './_generated/server'
import { v } from 'convex/values'

export const list = query(async (ctx) => {
  return await ctx.db.query('messages').order('desc').take(50)
})

export const send = mutation({
  args: { text: v.string(), author: v.string() },
  handler: async (ctx, args) => {
    await ctx.db.insert('messages', { ...args, timestamp: Date.now() })
  },
})
Enter fullscreen mode Exit fullscreen mode

React (Auto-Syncing)

import { useQuery, useMutation } from 'convex/react'
import { api } from '../convex/_generated/api'

function Chat() {
  const messages = useQuery(api.messages.list) // Auto-updates in real-time!
  const sendMessage = useMutation(api.messages.send)

  return (
    <div>
      {messages?.map(m => <p key={m._id}>{m.author}: {m.text}</p>)}
      <button onClick={() => sendMessage({ text: 'Hello!', author: 'Alice' })}>Send</button>
    </div>
  )
}
Enter fullscreen mode Exit fullscreen mode

Convex vs Firebase vs Supabase

Feature Convex Firebase Supabase
Real-time Automatic Listeners Channels
Functions TypeScript Node.js Edge/Postgres
Type safety Full Partial Partial
Queries Reactive Snapshot SQL

Need to extract data from any website at scale? I build custom web scrapers — 77 production scrapers running on Apify Store. Email me at spinov001@gmail.com for a tailored solution.

Top comments (0)