Skip to content

Latest commit

 

History

History
265 lines (202 loc) · 8.26 KB

File metadata and controls

265 lines (202 loc) · 8.26 KB

Backend Recommendation: Convex vs Supabase for Recursor

Executive Summary

Recommendation: Use Convex as the primary backend

After analyzing the PRD for Recursor (the live hackathon simulation), Convex is the clear winner for this project. The core requirements revolve around real-time interactions, live updates, and reactive data synchronization - all of which are Convex's primary strengths.

Detailed Analysis

Critical Project Requirements from PRD

  1. Real-time is the core feature (not just a nice-to-have)

    • Live feed of agent interactions
    • Real-time chat between visitors and agents
    • Dynamic leaderboards
    • <1s perceived latency requirement
    • WebSocket/SSE for live updates
  2. Scale requirements

    • 300-500 concurrent AI agents
    • 1,000+ concurrent viewers
    • Hundreds of simultaneous updates
  3. High-frequency interaction patterns

    • Agent "ticks" (event loop updates)
    • Continuous project status updates
    • Visitor-agent chat interactions
    • Real-time voting and scoring
  4. No authentication needed (current phase)

Why Convex Wins

Perfect Match for Core Requirements

Requirement Convex Supabase Winner
Real-time updates Native, automatic Requires setup ✅ Convex
<1s latency Optimistic updates built-in Manual implementation ✅ Convex
Live chat Reactive queries Requires WebSocket setup ✅ Convex
Agent state management Reactive, automatic sync Manual pub/sub ✅ Convex
High-frequency writes Designed for this Can handle but not optimized ✅ Convex
Type safety TypeScript-first Partial ✅ Convex
Developer velocity Instant hot-reload Slower iteration ✅ Convex

Specific Advantages for Recursor

1. Real-time Agent Simulation

// Convex makes agent updates trivial
export const updateAgentState = mutation({
  args: {
    agentId: v.string(),
    phase: v.string(),
    status: v.string()
  },
  handler: async (ctx, args) => {
    // Update automatically syncs to all viewers
    await ctx.db.patch(args.agentId, {
      phase: args.phase,
      status: args.status,
      lastUpdate: Date.now()
    });
  }
});

// React component automatically updates
function AgentView({ agentId }) {
  // This re-renders automatically when agent updates
  const agent = useQuery(api.agents.get, { id: agentId });
  return <div>{agent?.status}</div>;
}

2. Live Activity Feed

// Convex: Automatic real-time feed
export const getActivityFeed = query({
  handler: async (ctx) => {
    // Returns live, reactive data
    return await ctx.db.query("activities").order("desc").take(50);
  },
});

// Supabase: Would require manual WebSocket setup
// Plus handling reconnections, state sync, etc.

3. Optimistic Updates for <1s Latency

// Convex: Built-in optimistic updates
const sendMessage = useMutation(api.chat.send);
// UI updates instantly, server confirms later
await sendMessage({ text: "Hello" });

// Supabase: Must implement optimistic updates manually

4. Agent Event Loop ("Ticks")

// Convex: Easy to implement with scheduled functions
export const agentTick = internalMutation({
  handler: async (ctx) => {
    const agents = await ctx.db.query("agents").collect();

    // Process all agents in parallel
    await Promise.all(agents.map((agent) => processAgentTick(ctx, agent)));

    // Schedule next tick
    await ctx.scheduler.runAfter(1000, internal.simulation.agentTick);
  },
});

Performance & Scale

Convex handles the exact scale requirements:

  • ✅ 300-500 concurrent agents making updates
  • ✅ 1,000+ viewers receiving real-time updates
  • ✅ Automatic horizontal scaling
  • ✅ No infrastructure management needed

Developer Experience for Rapid Iteration

Given the aggressive timeline (MVP in 1-2 weeks):

  • Convex: Write functions, they work instantly
  • Supabase: Set up tables, RLS policies, WebSocket channels, etc.

Why Not Supabase?

Supabase is excellent, but not for this project:

  1. Real-time is secondary in Supabase - It's primarily a PostgreSQL database with real-time added on
  2. More complex setup - Need to configure:
    • Realtime channels
    • WebSocket connections
    • Manual optimistic updates
    • Pub/sub for agent coordination
  3. Overkill features - You don't need:
    • Complex SQL queries
    • Row-level security (no auth)
    • PostgreSQL extensions
    • File storage (artifacts can use CDN)

Migration Path (If Needed)

If you later need Supabase features:

  1. Keep Convex for real-time simulation
  2. Add Supabase for:
    • Authentication (Phase 2+)
    • Long-term analytics storage
    • File storage for artifacts

Cost Considerations

For a hackathon simulation:

  • Convex: Pay for function calls and database operations

    • Estimated: Moderate cost for event duration
    • Built-in cost controls via tick rate adjustment
  • Supabase: Pay for database size and bandwidth

    • Would also need additional real-time infrastructure
    • Potentially higher total cost

Implementation Speed Comparison

Time to implement core features:

Feature Convex Supabase
Real-time feed 30 min 2-3 hours
Agent chat 1 hour 3-4 hours
Live voting 30 min 2 hours
Agent state sync 1 hour 4-5 hours
Total MVP 1-2 days 4-5 days

Recommended Architecture

┌─────────────────┐
│   Next.js App   │
│  (Landing/UI)   │
└────────┬────────┘
         │
    Convex SDK
         │
┌────────▼────────┐
│     Convex      │
│   (Real-time)   │
├─────────────────┤
│ • Agent State   │
│ • Live Chat     │
│ • Activity Feed │
│ • Voting        │
│ • Leaderboards  │
└─────────────────┘
         │
         │ (Optional Phase 2+)
         ▼
┌─────────────────┐
│    Supabase     │
│  (If needed)    │
├─────────────────┤
│ • Auth          │
│ • File Storage  │
│ • Analytics     │
└─────────────────┘

Decision Matrix

Factor Weight Convex Supabase
Real-time capability 30% 10/10 6/10
Developer velocity 25% 10/10 7/10
Performance (<1s latency) 20% 10/10 6/10
Scale handling 15% 9/10 8/10
Cost efficiency 10% 8/10 7/10
Weighted Score 9.65 6.75

Final Recommendation

Use Convex immediately. It's purpose-built for exactly what Recursor needs:

  1. Real-time collaborative features
  2. Live reactive updates
  3. Low-latency interactions
  4. Rapid development timeline

You can ship the MVP in days, not weeks, and the real-time features will "just work" without complex configuration.

Next Steps

  1. Initialize Convex in the project:

    npx convex dev
  2. Define schema for agents, teams, projects, messages

  3. Implement core real-time functions:

    • Agent state management
    • Live activity feed
    • Chat system
    • Voting mechanism
  4. Build the UI with React + Convex hooks for automatic updates

  5. Deploy and iterate rapidly with hot-reload

Conclusion

For Recursor's requirements - especially the critical real-time simulation aspects with <1s latency requirements - Convex is the superior choice. It will enable you to build faster, with better real-time performance, and less complexity.

The project is essentially a massive real-time collaboration app, which is exactly what Convex was designed to handle.