Sketch Cloud runs completely on Lambda and DynamoDB: two services provided by Amazon to build and scale your infrastructure without using servers or instances - or at least with a minimal configuration needed for hardware. People call this “serverless”, which basically means we’re not doing any provisioning and focus on the code.
We’ll dive into the advantages and quirks of both services, but first let’s get one thing clear: this is not an article about microservices. These things go hand in hand quite often, but in our case we’re only going to focus on building an API with these services. If you’re interested in microservices, I would recommend checking out hackernews instead.
When dealing with uploading and handling a lot of images, it felt only natural to use S3 in combination with Lambda. Going down the rabbit hole, we started figuring out what we would need for the API and it made sense to work with Lambda for a consistent development experience. However, this would be a first for us, as we haven’t written a complete API on top of Lambda before. We figured that the ideal situation for building a product is where you don’t need to worry about dev-ops, scaling and all the meta-tasks. As a small development company, we like to focus on shipping great features and fixing bugs as fast as possible (who wouldn’t?), and ensure it all works smooth and efficient. For example:
We want to ensure people have a fast experience by avoiding uploading more files than needed. That’s why every file is represented by a hash. This hash is unique, but not unique to the person that created it. When you upload a file that is already present, it would make a reference to the other file - while still being unique to its document as a whole.
As a design tool and sharing service, the details should be right. As you share your link on any service (e.g. Slack), a nice little image shows up. This thumbnail image represents your document. As Lambda processes every image and turns it into thumbnails, it also generates an image using the same positioning algorithm used on the web.
As these Sketch Cloud links are meant to be shared, we felt it was needed to create a short URL. In our case it’s extremely important to guarantee the uniqueness of these strings, but still remain short. We figured out a way how to use DynamoDB and use an incremental reference to generate these ID’s.
I will not bore you with the small implementation details that can go wrong with Lambda and DynamoDB. Overall it’s very effective, but there’s still a lot of room for improvement:
As a developer I feel more comfortable with setting up an infrastructure, which also results in us being more aligned with what we can offer as a product. We still have a long road ahead, but it’s amazing to start off with a foundation that feels rock solid and gives the opportunity to focus mostly on our code. It’s great to see other people, companies and organizations building amazing products using similar or the same techniques, making the development experience much easier. Just take a look at apex.run and serverless.com.
For us, it’s making sure everyone can use the API without any trouble, while we keep providing the best features and experience. Read our showcase for more information on Sketch Cloud.