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:
WebSocket base URL using wss:// protocol
Geographic latitude of server location (decimal degrees)
Geographic longitude of server location (decimal degrees)
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"
}
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"
}
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"
}
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"
}
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"
}
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
| Region | Coverage Area | Typical Users |
|---|
| us-west | Western US, Pacific | California, Oregon, Washington |
| us-east | Eastern US, East Coast | New York, Virginia, Florida |
| us-central | Central US, Midwest | Illinois, Ohio, Texas |
| eu-central | Europe, Middle East | Germany, France, UK |
| ap-southeast | Asia Pacific | Singapore, 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:
- Deploy server to new location
- Obtain WebSocket URL
- Determine geographic coordinates
- Add entry to
SERVER_REGIONS:
"region-id": {
"url": "wss://your-server.onrender.com",
"lat": latitude,
"lon": longitude,
"ws_path": "/ws"
}
Best Practices
Client Implementation
- Auto-select nearest server based on user’s geolocation
- Fallback strategy if nearest server is unavailable
- Cache server selection for repeat visits
- Measure latency with ping tests before selecting
Server Management
- Keep coordinates accurate for optimal routing
- Monitor all regions for availability
- Load balance within regions if traffic is high
- Update URLs if servers are migrated