Serverless: From POC to Production

Posted by on December 17, 2019

Building serverless applications means that your developers can focus on their core product instead of worrying about managing and operating servers or runtimes, either in the cloud or on-premises.

Amazon Web Services

As FreeAgent begins to move to AWS, there are plenty of opportunities to take advantage of cloud-native technologies such as AWS Lambda. At the beginning of September, one such opportunity presented itself. We decided to create a new serverless implementation of our thumbnail previews for file attachments and company logos.

On-demand processing of thumbnails is well suited for serverless functions and gives the following benefits:

  • Increased agility
  • Reduced storage costs
  • Resilience to failure

We based our implementation on this excellent AWS blog post and CloudFormation Stack. Having this solid foundation gave us a significant boost in efficiency when writing our POC (proof of concept). We were able to integrate an on-demand serverless thumbnail preview service into parts of the development and integration environments in a matter of days. It took another ten weeks to finish the project. It certainly didn’t feel like an increase in agility.

Integration

Our POC was far from feature-complete, nor was it fully integrated into the FreeAgent application. Integrating the new serverless solution was one of the pit-falls we continued to fall in. Our application had previously generated thumbnails ahead of time, and this knowledge had leaked across multiple models, jobs, and views.

We used the following techniques to integrate the new solution:

  • Create new models to abstract business logic.
  • Use feature flags to divert the behavior to the new functionality.
  • Use a common interface to reduce the need for change in other places.

Environments

We made the Thumbnail Service (as it became known) a fully independent, albeit small, system. We removed any FreeAgent business logic from it and treated it as if it were a third party system.

Treating the system this way allowed us to:

  • Iterate changes quickly
  • Deploy Independently
  • Set a good precedent for future projects

Practically speaking, this decision forced all FreeAgent application environments to talk to the production Thumbnail Service. Doing this ensured:

  • Stability across environments
  • Strong authorization*
  • Fewer surprises when deploying to production

* We used IAM Authentication with API Gateway to ensure requests from each environment were correctly authorized to access the thumbnails they were requesting.

Visibility

Creating a separate service or application requires an understanding of how the service will perform in production. We’re using new technologies in AWS Lambda and API Gateway, two serverless resources from AWS to offer high scalability. Nevertheless, we must understand how our system is performing in the production environment and what impact that has.

We took the following steps to ensure the visibility of the system:

  • Define a Service Specification
  • Create Alarms based on our Specification
  • Ensure logging is accessible
  • Create business-focussed dashboards, e.g Requests per Logo
  • Create system-focussed dashboards, e.g API Latency

Previously, we had a few of these metrics, but not to the granularity which exists now. This visibility was vital in ensuring we delivered a stable and reliable service.

Ownership

One of the key benefits of the project was that it was run with a handful of people. Reaching out to key stakeholders and the operations team only when it was necessary.

A single team managed deployments, application code, infrastructure, and testing. Help was still available when needed, but bottlenecks between teams were reduced considerably.

AWS Services such as Lambda and API Gateway make strives to remove the complexity of managing servers (as the name suggests). However, it would be disingenuous to state moving to this new serverless stack removed all complexity. Servers may not be being managed (by us) anymore, but the knowledge the team needed to acquire was broad across multiple domains.

Stability, Improvements & Changes

Generating on-demand thumbnails on AWS Lambda gave us more benefits:

  • Isolated environments increased stability
  • Fixing bugs benefit past and present thumbnails

However, swapping to an on-demand serverless implementation requires a mind shift.

One example was rendering invisible thumbnails. Thumbnails not shown were costing us money. Actual money. With a tangible cost. To tackle this issue, we made some improvements which reduced calls to our new service by 600%.

Conclusion

Overall, the project was a success. The new technologies we used created business value and lessons learned for the future. Serverless technologies may reduce the need for managing servers, but there is still a lot of peripheral work in ensuring a service is ready for production.

Let’s talk tools

Posted by on December 2, 2019

In a recent workshop, we were talking about our toolchains, recommending tools to one another that we couldn’t live without. We shared them with the rest of the engineering team and they gave further suggestions of their setups. I’ve collected them all together so you can find your new favourite tool and increase your productivity! Let’s get into it.

Browser Extensions

Octotree is a browser plugin that gives you a tree of the repo you’re looking at, giving you a way to nose through the repo without having to open countless tabs and go up and down the file explorer!

A look at Octotree for the repo for our gem, Hermod.
Here’s how it looks on the repo for our gem, Hermod.

Refined GitHub improves GitHub’s UI/UX by simplifying some of its interface and adding useful buttons & links to make your life a bit easier as a GitHub user. Some of their changes have been brought into GitHub itself! Check out their repo for highlights.

CodeClimate is our service of choice for measuring code quality and linting pull requests. Their browser extension adds inline warnings to GitHub to help you find problems in your code more easily! It also highlights test coverage so you can focus on which bits of your code need more specs.

Fake Data generates fake but realistic looking data at the press of a button. This is particularly useful during development when you want to fill your forms with random data but can’t think of new test names.

Desktop Apps

Git clients

Git occasionally gets a bad rap for its UI, with people saying that it can be confusing to use and hard to remember all the commands that it provides. Thankfully, others who also had these gripes made apps to wrap Git and make it easier to use for everyone! Some of our favourites are Fork, Sublime Merge and GitHub Desktop.

Note taking

Bear is a really beautifully designed Markdown note taking app available for macOS and iOS. In the words of one of our engineers, Simon: ‘I use it to draft testing tickets (You can copy a block of text/Markdown and, when you paste it into a Trello checklist item, it’ll create an item per line of text) as well as keep notes on everything from projects I’m working on to TODO lists for all the DIY I might one day get around to.’

Quiver is a programmer’s notebook with syntax highlighting, tagging, search, and a whole load of other features that make it easy to save and find those handy little snippets of code that you might otherwise file away in a GitHub gist.

Miscellaneous

CloudApp & LICEcap let you easily capture a screenshot or screen recording and upload it as an image/GIF/video then share it. The screen recording most is particularly useful for quickly documenting bug reports or showing someone how to do something rather than trying to describe what they need to click on, etc.

Rectangle is for moving and resizing windows in macOS using keyboard shortcuts or snap areas. If you want to quickly compare two windows, you can use it to resize the windows to be half as wide and send them to either sides of the screen.

Next Meeting connects to your calendar and shows when your next meeting is in your menu bar. It also lets you quickly open up Google Hangouts or Zoom calls where those meetings are taking place.

Dash is an API Documentation Browser and Code Snippet Manager. Dash stores snippets of code and instantly searches offline documentation sets for 200+ APIs, 100+ cheat sheets and more. You can even generate your own docsets or request docsets to be included! For us, that means we can have gem docs downloaded on our laptops ready to access at the press of a shortcut!

Command Line Tools

RipGrep is a search tool, like grep, but much faster. (Honourable mention the similarly blazing fast The Silver Searcher.)

From RipGrep’s GitHub repo.

bat is a tool to print the contents of files to the terminal. Like cat but with syntax highlighting, Git integration and a built-in pager to stop large files spilling into your terminal!

From bat’s GitHub repo.

tree visualises the contents of a directory by showing the full tree. Be warned though, on big directories, this will fill your terminal in no time, not to mention reading ‘ignored’ files like node_modules etc.

Hstr is a tool for searching your command history. If you’ve ever used Ctrl-R to search through previous commands, this is like that but x 5. It gives you a fuzzy search and visual selection through your terminal history. It’s the cat’s pyjamas.

Fzf, similarly, is a tool for searching/fuzzy finding but for all the things. It can be used to search through files, command history, hostnames, processes, git commits. You name it, it can probably list it for searching.

From fzf’s GitHub repo.

gron processed JSON and changes it into a form that’s easier for grep (or RipGrep!) to search through. It also has a flag to support reassembling the results to JSON!

jq offers a different solution to the problem that Gron is solving. Rather than destructuring JSON, jq lets you directly search, slice and filter JSON. In its own words, it’s like sed for JSON!

tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal.

htop is an interactive process viewer for Unix systems. It shows lots of useful stats like processor utilisation, load average and uptime!

An example of htop running on my laptop.

reachable supports checking if a website is available from the command line.

Running reachable against this blog

s (yes, just the letter S) allows you to open web searches from the terminal straight into your browser. Useful for quick look ups!

And finally:

tldr are like man pages for those in a hurry. Rather than containing the full manual for a command or tool, they contain common uses of that tool. It’s very useful if you’re looking for general usage for a tool, but don’t want to wade through the man pages!

From tldr’s website.

That’s all for now! Thanks for reading and I hope you found a new tool that you enjoy!