Skip to main content

Overview

The servers module defines all available server regions, their WebSocket endpoints, and geographic coordinates for latency-based routing. Location: backend/src/config/servers.py
Current Deployment: The production frontend currently uses a hardcoded AWS Kubernetes endpoint (wss://3.149.10.154.nip.io/ws) defined in ServerDiscovery.js, not these Render.com endpoints. The SERVER_REGIONS configuration provides alternative deployment options and a foundation for implementing dynamic multi-region routing in the future.

Server Regions Dictionary

SERVER_REGIONS = {
    "us-west": {...},
    "us-east": {...},
    "us-central": {...},
    "eu-central": {...},
    "ap-southeast": {...}
}
Dictionary mapping region identifiers to server configuration objects.

Region Configuration Schema

Each region contains the following fields:
url
str
required
WebSocket base URL using wss:// protocol
lat
float
required
Geographic latitude of server location (decimal degrees)
lon
float
required
Geographic longitude of server location (decimal degrees)
ws_path
str
required
WebSocket endpoint path (always "/ws")

Available Regions

US West (Oregon/Portland)

"us-west": {
    "url": "wss://languagedetection-9l89.onrender.com",
    "lat": 45.5155,  # Portland, OR
    "lon": -122.6789,
    "ws_path": "/ws"
}
Region
string
us-west
Location
string
Portland, Oregon, USA
Coordinates
string
45.5155°N, 122.6789°W
WebSocket URL
string
wss://languagedetection-9l89.onrender.com/ws

US East (Virginia)

"us-east": {
    "url": "wss://languagedetection-virginia.onrender.com",
    "lat": 37.5407,  # Virginia
    "lon": -77.4360,
    "ws_path": "/ws"
}
Region
string
us-east
Location
string
Virginia, USA
Coordinates
string
37.5407°N, 77.4360°W
WebSocket URL
string
wss://languagedetection-virginia.onrender.com/ws

US Central (Ohio)

"us-central": {
    "url": "wss://languagedetection-ohio.onrender.com",
    "lat": 39.9612,  # Ohio
    "lon": -82.9988,
    "ws_path": "/ws"
}
Region
string
us-central
Location
string
Ohio, USA
Coordinates
string
39.9612°N, 82.9988°W
WebSocket URL
string
wss://languagedetection-ohio.onrender.com/ws

EU Central (Germany)

"eu-central": {
    "url": "wss://languagedetection-europe.onrender.com",
    "lat": 48.1351,  # Munich, Germany
    "lon": 11.5820,
    "ws_path": "/ws"
}
Region
string
eu-central
Location
string
Munich, Germany
Coordinates
string
48.1351°N, 11.5820°E
WebSocket URL
string
wss://languagedetection-europe.onrender.com/ws

AP Southeast (Singapore)

"ap-southeast": {
    "url": "wss://languagedetection-singapore.onrender.com",
    "lat": 1.3521,  # Singapore
    "lon": 103.8198,
    "ws_path": "/ws"
}
Region
string
ap-southeast
Location
string
Singapore
Coordinates
string
1.3521°N, 103.8198°E
WebSocket URL
string
wss://languagedetection-singapore.onrender.com/ws

Usage Examples

Accessing Region Configuration

from config.servers import SERVER_REGIONS

# Get US West configuration
us_west = SERVER_REGIONS["us-west"]
print(f"URL: {us_west['url']}")
print(f"Location: {us_west['lat']}, {us_west['lon']}")

# Build full WebSocket URL
full_url = us_west["url"] + us_west["ws_path"]
print(f"Connect to: {full_url}")

Iterating Over All Regions

from config.servers import SERVER_REGIONS

for region_id, config in SERVER_REGIONS.items():
    print(f"{region_id}: {config['url']}")
Output:
us-west: wss://languagedetection-9l89.onrender.com
us-east: wss://languagedetection-virginia.onrender.com
us-central: wss://languagedetection-ohio.onrender.com
eu-central: wss://languagedetection-europe.onrender.com
ap-southeast: wss://languagedetection-singapore.onrender.com

Client-Side Region Selection

// JavaScript example for selecting nearest server
const SERVER_REGIONS = {
  "us-west": {
    url: "wss://languagedetection-9l89.onrender.com",
    lat: 45.5155,
    lon: -122.6789,
    ws_path: "/ws"
  },
  // ... other regions
};

function calculateDistance(lat1, lon1, lat2, lon2) {
  // Haversine formula
  const R = 6371; // Earth's radius in km
  const dLat = (lat2 - lat1) * Math.PI / 180;
  const dLon = (lon2 - lon1) * Math.PI / 180;
  const a = Math.sin(dLat/2) * Math.sin(dLat/2) +
            Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) *
            Math.sin(dLon/2) * Math.sin(dLon/2);
  const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
  return R * c;
}

function selectNearestServer(userLat, userLon) {
  let nearest = null;
  let minDistance = Infinity;
  
  for (const [regionId, config] of Object.entries(SERVER_REGIONS)) {
    const distance = calculateDistance(userLat, userLon, config.lat, config.lon);
    if (distance < minDistance) {
      minDistance = distance;
      nearest = { regionId, ...config };
    }
  }
  
  return nearest;
}

// Get user's location and select server
navigator.geolocation.getCurrentPosition((position) => {
  const server = selectNearestServer(
    position.coords.latitude,
    position.coords.longitude
  );
  const ws = new WebSocket(server.url + server.ws_path);
  console.log(`Connected to ${server.regionId}`);
});

Geographic Coverage

RegionCoverage AreaTypical Users
us-westWestern US, PacificCalifornia, Oregon, Washington
us-eastEastern US, East CoastNew York, Virginia, Florida
us-centralCentral US, MidwestIllinois, Ohio, Texas
eu-centralEurope, Middle EastGermany, France, UK
ap-southeastAsia PacificSingapore, Malaysia, Indonesia

Latency Considerations

Choosing the nearest server region reduces:
  • WebSocket connection latency
  • Audio data transmission time
  • Round-trip time for responses
Typical latency ranges:
  • Same region: 10-50ms
  • Adjacent region: 50-100ms
  • Cross-continent: 100-300ms

Infrastructure

All servers are hosted on Render.com with:
  • Automatic HTTPS/WSS encryption
  • Global CDN distribution
  • Automatic scaling
  • Health monitoring

Adding New Regions

To add a new server region:
  1. Deploy server to new location
  2. Obtain WebSocket URL
  3. Determine geographic coordinates
  4. Add entry to SERVER_REGIONS:
"region-id": {
    "url": "wss://your-server.onrender.com",
    "lat": latitude,
    "lon": longitude,
    "ws_path": "/ws"
}

Best Practices

Client Implementation

  1. Auto-select nearest server based on user’s geolocation
  2. Fallback strategy if nearest server is unavailable
  3. Cache server selection for repeat visits
  4. Measure latency with ping tests before selecting

Server Management

  1. Keep coordinates accurate for optimal routing
  2. Monitor all regions for availability
  3. Load balance within regions if traffic is high
  4. Update URLs if servers are migrated

Build docs developers (and LLMs) love