Create a good serverless developer experience
What makes a good developer experience?
I asked twitter and it was all over the place. A theme emerged:
Good developer experience is when tools make your job easier, get out of the way, and let you focus on your code
How do you setup a serverless project for good DX?
It comes down to 3 features:
- Infrastructure-as-code
- Fast deploys
- Tooling for common tasks
Infrastructure-as-code
As mentioned in the Getting Started chapter, I like to use the open source Serverless Framework with AWS. When using Netlify and Vercel you don't need Serverless because config-as-code is baked into their philosophies.
You write a configuration file, add it to version control, and that's your infrastructure. Nothing happens outside that configuration file.
This means that:
- Your deploys are repeatable. Run deploy, get the same result every time. The same functions, the same queues, the same caching servers, everything.
- Same infrastructure in test as in prod Subtle differences between test environments and production are a waste of time. Big part of why Docker got popular.
- Share infrastructure between the team. Ever had to ask a team member what environment variable they used for a thing? I have. After 2 hours of digging into the problem and realizing it's a configuration issue. π€¦ββοΈ
- Infrastructure that always fits your feature branch A common problem are new features with different infrastructure. Like adding a new queue or cloud function. Instead of setting it up every time you test, infra-as-code can do it for you.
- Spend time in the tools you like, not confusing web UI We're engineers and we like building things. Not clicking around a web UI doing repetitive tasks that take 20 minutes.
Fast deploys
The shorter your feedback cycle, the faster you can work.
On the frontend we have local dev servers and hot reloading. You see the result almost as fast as you write the code.
On the backend things are trickier.
You make a change ... now what? If you have unit tests, they show you part of the picture. The specific scenarios you thought to test, the methods you're exercising, the particular inputs.
All great.
But unit tests can't tell you your system works. That's where bugs come from βΒ systems complexity.
You can simulate the environment and run your tests. That works to an extent, but it's never perfect.
Your best bet is to make deploying to a staging, QA, or production environment fast enough to use for development. With serverless, that becomes possible.
You could even set it up so that pushing to GitHub deploys every branch. Netlify and Vercel call it pull request previews.
How fast deploys work
Here's how the flow works:
- Hit deploy
- Compile your code locally on your fast developer machine. Since your code is small, it compiles in seconds.
- Compile your infrastructure the serverless framework compiles your infrastructure into a config file for the target platform. With AWS that's SAM.
- Upload your bundle this is the slowest part.
- Infrastructure sets itself up using your config the platform sets itself up. Servers appear, queues go up, etc. Takes a few seconds
- You're ready to go