Video:

Setting Sensible Timeouts In Your Server

February 28, 2021

Course Instructor: Elliot Forbes

Hey Gophers! My name is Elliot and I'm the creator of TutorialEdge and I've been working with Go systems for roughly 5 years now.

Twitter: @Elliot_f

Timeouts within your REST APIs can be an important safety mechanism that helps prevent your server from crashing due to too many long running requests.

They can also be really helpful in preventing unnecessary resource utilization if you have time-sensitive tasks that must be complete in a certain time window or they fail. At a previous company, we had a 2 second time window in which we had to respond or that particular action would fail, therefore, it made sense to set the timeout to be quite aggressive on this service to prevent some requests lasting longer than the 2 seconds and potentially taking away valuable compute resources away from other incoming requests.

In this video, we are going to look at how we can modify our existing REST API project in order to add some sensible timeouts.

The Code

println("hi")

Conclusion

Awesome, so in this video, we’ve looked at how we can modify our existing REST API and add some sensible timeouts. We’ve also been able to test this by adding a test endpoint that runs longer than the length of our set timeout.