openpredictionmarkets / socialpredict

Easy to Deploy Prediction Market Platform
https://github.com/openpredictionmarkets/socialpredict
MIT License
54 stars 10 forks source link

Decide How to Calculate Market Price Projections #270

Closed pwdel closed 1 month ago

pwdel commented 1 month ago

Considerations for Architecting Probability Projection in a Prediction Market

1. Frontend-Based Calculation (React)

2. Backend-Based Calculation (Golang) with API Call

3. Hybrid Approach

Recommendation

Consider profiling network latency and backend load under simulated user conditions to make an informed decision based on actual performance metrics.

Comparison of Computational Intensity and Network Latency: Frontend vs. Backend Calculation

Assumption Frontend Calculation (React) Backend Calculation (Golang)
Calculation Complexity Simple division (1 operation) Iterating through 10,000 bets
Network Speed (Low) - No network overhead.
- React calculation: negligible impact on performance.
- High latency due to slow network.
- Network overhead could be significant.
- Golang computation: efficient, but the result depends on 10,000 operations, slightly increasing processing time.
Network Speed (Medium) - No network overhead.
- React calculation: negligible impact on performance.
- Moderate latency with some network delay.
- Network overhead: present but not significant.
- Golang computation: still efficient, but overall latency depends on API response time.
Network Speed (High) - No network overhead.
- React calculation: negligible impact on performance.
- Low latency due to fast network.
- Network overhead: minimal.
- Golang computation: quick, with low additional processing time for 10,000 operations.
Frontend Device (High-End) - Immediate calculation.
- Minimal impact on CPU/GPU.
- N/A
Frontend Device (Low-End) - Slight delay due to lower processing power, but still relatively fast. - N/A
Overall Network Latency - None (Calculation is local). - Low to high depending on network speed.
- Adds to the total response time, which includes processing and data transmission.
Backend Load - N/A - High if multiple users make concurrent requests.
- Golang handles 10,000 operations efficiently, but under heavy load, the server might experience a slight delay.

Summary

The choice between frontend and backend calculations depends on your priorities: responsiveness vs. accuracy. Frontend calculations offer immediate feedback but may lack real-time accuracy. Backend calculations ensure consistency across users but at the cost of potential network latency and increased computational demands.


Network Latency Ranges for Backend Calculation

Network Speed Latency Range (Low) Latency Range (High) Notes
Low (e.g., 2G/3G, congested network) 500ms - 1.5s 1.5s - 5s - Significant delay in API calls.
- Can impact user experience negatively, especially if calculations are frequent.
Medium (e.g., 4G LTE, average Wi-Fi) 100ms - 300ms 300ms - 1s - Moderate delay, but generally acceptable for most users.
- Network overhead still noticeable with frequent requests.
High (e.g., 5G, Fiber, fast Wi-Fi) 20ms - 50ms 50ms - 100ms - Minimal delay, providing a responsive experience.
- Network overhead is low, even with frequent API calls.
Local Network (e.g., Docker on the same host) 1ms - 10ms 10ms - 30ms - Very low latency, almost negligible.
- Only slight overhead from Docker’s network stack.

Summary

Implications

These ranges should give you a clearer idea of the potential delays users might experience based on their network conditions.