Skip to content

Instantly share code, notes, and snippets.

@arpy8
Last active April 29, 2025 20:04
Show Gist options
  • Save arpy8/ad8856159674f49cc0358d45ed614541 to your computer and use it in GitHub Desktop.
Save arpy8/ad8856159674f49cc0358d45ed614541 to your computer and use it in GitHub Desktop.
Why Hugging Face Spaces Performs Better Than Vercel for BaatCheet

Why Hugging Face Spaces Performs Better Than Vercel for BaatCheet

What is BaatCheet?

BaatCheet is a real-time video conferencing application that allows users to create and join virtual meeting rooms for face-to-face communication. The name "BaatCheet" comes from Hindi, meaning "conversation" or "chat." The application features:

  • Instant room creation and joining
  • Real-time video and audio streaming
  • Text chat alongside video conferences
  • Screen sharing capabilities
  • Low-latency peer-to-peer connections using WebRTC
  • Socket.IO for signaling and real-time event handling

Architecture Differences

  1. Container-based vs Serverless

    • Hugging Face Spaces: Uses a persistent container-based deployment that stays running
    • Vercel: Uses serverless functions that "sleep" after inactivity, requiring "cold starts"
  2. WebSocket Performance

    • Hugging Face Spaces: Better suited for long-lived WebSocket connections
    • Vercel: Designed primarily for HTTP requests, with WebSocket connections subject to timeouts (typically 10s)

Impact on BaatCheet's Room Joining

The room joining process in BaatCheet involves:

  1. Establishing a Socket.IO connection
  2. Initializing media streams
  3. Emitting a 'join-room' event
  4. Waiting for peer connections

On Vercel, if the function has gone cold, this entire sequence faces additional latency:

  • 2-5 seconds for the serverless function to wake up
  • Potential timeouts during WebSocket handshakes
  • Delays in media stream negotiation

Technical Specifics

BaatCheet's architecture using Socket.IO for real-time communication:

// Server-side (affected by cold starts on Vercel)
const io = new Server(server, {
    cors: {
        origin: "*",
        methods: ["GET", "POST"]
    }
});

// Client-side
this.socket = io(window.location.origin);
this.socket.emit('join-room', roomId); // This call experiences delay on Vercel

Recommendations

  1. Keep Vercel functions "warm" with regular ping mechanisms (check out wakey-wakey)
  2. Implement connection retry logic with exponential backoff
  3. Add performance monitoring to identify specific bottlenecks
  4. Consider a hybrid approach: Vercel for static assets, HF Spaces for WebSocket server

Conclusion

For optimal real-time performance in BaatCheet, Hugging Face Spaces remains the better deployment option due to its container-based architecture that better supports persistent WebSocket connections required for video chat applications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment