Home Projects Portfolio Dashboard Export PDF Log in

Scaling Interview Rooms: Dynamic Capacity and Robust Data Handling

In the fast-paced world of recruitment, few things are as frustrating as a broken interview link or a virtual room that's unexpectedly full. For the Remax NOA Oficial project, managing virtual interview rooms efficiently and reliably became a critical focus. Initially, the system faced challenges with rigid capacity limits and fragile database queries, leading to disruptions in the human resources (RRHH) workflow.

The Problem with Static Limits and Brittle Queries

The initial setup for virtual interview rooms, likely powered by a service like Daily.co, relied on hardcoded capacity limits. This meant every room was stuck at a fixed number of participants (e.g., 4 people), regardless of the actual group size or specific interview requirements. When a larger panel or group interview was needed, the system simply couldn't accommodate it, leading to a poor user experience and logistical headaches. Furthermore, the system's WhatsApp webhooks used strict .single() database queries to fetch room data. While .single() is useful when you absolutely expect one and only one record, it throws an error if no record is found or if multiple records surprisingly match, causing the entire webhook process to fail and resulting in 'broken links' for users.

Embracing Dynamic Capacity Management

To address the capacity bottleneck, the team refactored the system to use dynamic capacity checks. Instead of a hardcoded number, the maximum capacity is now pulled from a capacidad_maxima (maximum capacity) setting associated with the group or interview type. This change involved:

  1. Increasing Daily.co Limits: The underlying Daily.co integration was updated to support up to 10 participants, providing a higher ceiling for larger interviews.
  2. Referencing Group-Specific Settings: The system now dynamically checks a group's configured maximum capacity for each interview room, making the system far more flexible.

Here's a simplified illustration of how a dynamic capacity check might look:

// Old way: Hardcoded capacity
const MAX_HARDCODED_PARTICIPANTS = 4;
const isRoomFullOld = currentParticipants >= MAX_HARDCODED_PARTICIPANTS;

// New way: Dynamic capacity from configuration
async function checkDynamicRoomCapacity(groupId, currentParticipants) {
  const { data: groupConfig, error } = await supabase
    .from('app_config') // Using a generic table name
    .select('max_room_capacity')
    .eq('group_id', groupId)
    .limit(1)
    .maybeSingle();

  if (error) {
    console.error('Error fetching group capacity:', error.message);
    return true; // Default to full on error for safety
  }

  const maxCapacity = groupConfig?.max_room_capacity || 4; // Fallback to default
  return currentParticipants >= maxCapacity;
}

// Example usage:
// const roomIsFull = await checkDynamicRoomCapacity('interview-group-id', 7);

This approach ensures that the system can adapt to varying interview sizes without requiring code changes, providing a much more scalable solution.

Building Robustness with maybeSingle()

The second critical improvement involved enhancing the robustness of database queries, particularly within the WhatsApp webhooks. The original .single() query was replaced with a combination of .limit(1).maybeSingle(). This seemingly small change has a significant impact on error handling:

  • .single(): Expects exactly one record. If zero or more than one record is found, it throws an error.
  • .limit(1).maybeSingle(): Limits the result set to at most one record. If one record is found, it returns that record. If zero records are found, it returns null for the data, without throwing an error. This allows for graceful handling of scenarios where a record might not exist, preventing webhook failures.

Consider this code illustrating the difference:

// Problematic: Throws error if no record matches 'non-existent-id'
async function getRoomStrict(roomId) {
  const { data, error } = await supabase
    .from('interview_rooms')
    .select('*')
    .eq('room_id', roomId)
    .single(); // Will throw error if no record or >1 record
  if (error) console.error('Strict query failed:', error.message);
  return data;
}

// Robust: Returns null for data if no record matches, no error for 0 results
async function getRoomSafely(roomId) {
  const { data, error } = await supabase
    .from('interview_rooms')
    .select('*')
    .eq('room_id', roomId)
    .limit(1)
    .maybeSingle(); // Returns null data if no record, no error for 0 records
  if (error) console.error('Safe query encountered error:', error.message);
  return data;
}

// Usage example:
// const strictResult = await getRoomStrict('non-existent-id'); // Might throw or log error
// const safeResult = await getRoomSafely('non-existent-id');   // safeResult will be null, no error thrown

This change significantly improved the reliability of webhook interactions, ensuring that the system continues to function smoothly even when unexpected data conditions arise.

Actionable Takeaway

When designing systems, prioritize flexibility and defensive programming. Avoid hardcoding limits that can change, and always consider the edge cases for data retrieval. Using dynamic configurations and robust database query patterns like limit().maybeSingle() can prevent common pitfalls, leading to a more resilient and user-friendly application.


Generated with Gitvlg.com

LAUTARO NICOLAS ZULETA

LAUTARO NICOLAS ZULETA

Author

Share: