Async Rust with Tokio
Most Grok Insider services use Tokio as the async runtime: many sockets, one process, no thread-per-request.
Minimal server shape
#[tokio::main]
async fn main() {
// bind, accept, spawn per connection
}
Mental model
.awaityields while I/O is pending.tokio::spawnruns independent tasks on the runtime.- Prefer structured concurrency: cancel children when the parent ends.
Tips for APIs
- Share state with
Arc. - Use a connection pool for Redis/DB.
- Add timeouts on outbound calls.
Async is not “free threads” — it is cooperative scheduling. Keep CPU-heavy work off the async executor.
