An alternate title for this post might be
Processing API Requests with a Queue. We recently had a project where we were expecting a burst of high traffic and heavy load on some API endpoints. We wanted to make sure that we could handle all of the traffic, even if the processing time was affected - dropped requests were not an option. After doing quite a bit of research this post is what we came up with. In the end this strategy worked well for our purposes, but we did identify some ways that we would improve it in the future.
Also this same strategy will work for any long-running api request. Things like reporting for example, where you need to be able to make a request but it may take a very long (and possibly indeterminate) amount of time to complete. Please forgive the tone of the document, it is being adapted from my notes and it isn’t in conversational form. It’s likely that there may be some things that I should expand upon, so if anything needs clarification please feel free to ask in the comments.comments
Recently I came across an error using postgres that stumped me for a while so I wanted to document it for next time. I was issuing an update statement to a table that had no numeric columns, but received the error:
ERROR: value overflows numeric format. Not only did my statement not affect any numeric columns, the table itself didn’t have any numeric columns. The actual problem ended up being some malformed json that I was trying to insert into a
jsonbcolumn. The json had a value like
300e715100which was actually part of a hashed string, but the json serializer I was using incorreclty identified it as a very large scientific notiation number, and so did not quote it. Because postgres cannot deal with a number that large it throws the error. Quoting the value properly fixed the problem. I also want to note that the error would not happen with
json, only with
jsonbbecause postgres is actually parsing the document.
You can try the code and see the error for yourself here: http://dbfiddle.uk/?rdbms=postgres_9.6&fiddle=1584330f148ab0e9ed72529dfb466a12comments
Today I learned that postgres allows you to use a subselect in an update statement using a special syntax. This allows you to update a record from other data in the system easily (without remembering the weird update-with-join syntax) or to have an update syntax that more closely resembles an insert statement. For example:
The subselect can be any query, just return your columns in the same order as the column list you provide. Here is the relevant documentation if you want to read further: https://www.postgresql.org/docs/current/static/sql-update.htmlcomments
There are few things I have learned in my programming career that have paid off like higher order functions.comments
At MotorsportReg we have customers all over the world so there is never a good time for maintenance or downtime. Historically, we used multiple application servers with sticky CFML sessions on the load balancer. Deploying code often meant interrupting users to deploy changes which is unacceptable. We needed more flexibility.
Sidecar is our solution, an external session management plugin for ColdFusion. Inspired by sessions in expressjs, we separated the persistence from the session management itself so you can plug in your favorite tech to fill that need - we wrote
redis_session_store.cfcfor our own needs, but all you have to do is implement the simple API for your preferred backend (memcached, couchdb, database, etc). If you implement your own storage adapter, please get in touch!
Once you have the potential for multiple servers to access session data at the same time, you’ll realize that
<cflock>no longer offers the expected protection. We also wrote a separate distributed locking library, cfml-redlock, to make concurrent access safer, click here for some more info on that project).
This software is used in production. We wanted to open source it so that others can benefit but, also, selfishly in the hope that other companies will test it, file issues, or contribute. Implementation is simple - take a look at the tests and you should be able to get around pretty quickly. We plan to support Adobe ColdFusion 10+ and Lucee 4.5+ with this library.
If you have a passion for speed or love cars, motorcycles or karts, check out MotorsportReg. We have more than 5,000 track days, autocross, races and tours you can get involved with - chances are there is something happening near you!comments