Backpressure checking

Changes to accomodate connections being exhausted in the database. This code is mostly intended to illustrate good practice, but does also prevent out of memory style issues if the database is overloaded (something that other projects would also do in a production style situation).