Keeping D3 Visualizations Current with AWS Lambda
It has been about a year and a half since I set up my first Linux server and I still get nightmares.
It barely even counted as a real server. CentOS running on a Dell OptiPlex 9010 for the purpose of sharing a MySQL database with a maximum of 10 concurrent users. Pretty basic job in hindsight, but picking a Linux distribution and getting everything configured for any server job takes time and tons can go wrong if servers are not “your thing”.
One of the articles I stumbled across that stayed with me was this post on the inherent virtue of lazy SysAdmins. It turns out what looks like laziness might actually just be preparedness–which I will attempt to replicate with charts. Lazy visualization practitioner is best visualization practitioner.
What is the best way to keep charts up to date?
The chart I’m working on is a single-page election data explorer that currently has national polling estimates and delegate counts for the United States election.
Naturally everything is designed to be responsive and is a continuation of my efforts to make mobile friendly charts. D3 is being used to manipulate the DOM aggressively. Check it out in a new window and play around. What I don’t want to do is have to go in and adjust code or manually upload new data every time a new poll is realased.
Thanks to the lazy sysadmins at Amazon Web Services and awesome Huffington Post Data team, I’m using the Lambda service and Pollster API to keep the polling portion of the chart up-to-date. Lambda let’s you run snippets of code at set intervals or in response to events without having to spin up servers. Repeat, no server administration-ing necessary.
Total cost to run this function every day or even a few times a day rounds to $0.00 per month.
Instead of hitting the Huffington Post API with dozens of extra API calls (dozens!) and making client browsers do the work of data manipulation, Lambda removes the need for a lot of redundant computing.
Basically free for this use case.
No servers to break at the worst times.
Way to save client browsers from extra work/data
Keep charts updated even while on vacation.