Swizec Teller - a geek with a hatswizec.com

    Your serverless questions, answered

    When talk comes to serverless, engineers have lots of questions. Here are some answers 😊

    What the heck is serverless?

    Serverless is other people's servers running your code. The latest step in the evolution from full DoItYourself servers running on a machine you own towards "I just want a piece of code to run when you hit a URL"

    The core innovation are virtual servers small and fast enough to wake up on every request. This enables perfect automatic scaling to your traffic.

    PS: You can see me answer some of these in a recent video 👇

    ‌What would be the best way to change data (like toggling a boolean value via Lambda) to change the state of the SSG/ISR Next.js app?

    A common use-case for serverless is to rebuild your JAMStack static website when data changes. User action or database event triggers your serverless function, your code makes a request to the "Redeploy Webhook" that most providers offer, and voila: updated website.

    Calling the webhook is a basic fetch() request. You could even do it from the browser ✌️

    ‌So should you be using lambda instead of firebase cloud function?

    Choosing providers is tricky. Depends on what you're doing and what you're looking for.

    Firebase is great for getting started. Comes with lots of features and application logic. The downside is that their API and documentation can feel like it wasn't built for modern JavaScript.

    And when you outgrow Firebase's native way of doing things, or need anything custom at all, you're shit out of luck.

    I like AWS Lambda because it's basic 👉 plain JavaScript function running at a URL. Do what you want.

    Serverless Handbook for Frontend Engineers – free chapter

    Dive modern backend. Understand any backend.

    Serverless Handbook taught me high-leveled topics. I don't like recipe courses and these chapters helped me to feel like I'm not a total noob anymore.

    The hand-drawn diagrams and high-leveled descriptions gave me the feeling that I don't have any critical "knowledge gaps" anymore.

    ~ Marek C, engineer

    Start with a free chapter and email crash course ❤️

    Join over 14,000 engineers just like you already improving their careers with my letters, workshops, courses, and talks. ✌️

    ‌Can you talk about the pros and cons of freelancing with serverless as your specialty?

    In freelancing and consulting circles this is called "positioning" or "niching down". Great terms to Google.

    A basic positioning statement would be "I transition growing B2C startups to serverless so they can scale faster without downtime".

    The goal is to sell a business benefit and be known as The Person for your thing. Makes you easier to hire, easier to recommend, faster to remember.

    ‌Does lambda work with relational database? Or does it just work with dynamo?

    AWS Lambda can connect to any database. If there's a JavaScript library for your database of choice, you can use it.

    Dynamo is used in tutorials because it's quick to set up and unlike traditional databases, you need not worry about swamping your database with requests.

    But dynamo isn't great for typical application data.

    ‌Is not there a problem with the cold start for apps, which has low traffic?

    Cold starts are a common concern with serverless. That's when a new user hits your dormant server and needs to wait for code to warm up.

    Huge problem before serverless came along. Services like Heroku, shared hosting, and even (mismanaged) DIY servers experienced huge cold start latency.

    1 second to get an API response is no good. 😅

    With serverless and JavaScript, cold starts sit in the 100ms to 200ms range. Tiny simple servers are quick to wake up.

    If that's too slow, AWS recently added a feature that keeps your lambda warm.

    ‌What is your preferred cloud provider for serverless?

    Personally I like AWS. It's become the industry standard, has more services than I'll ever need, and it's free for all but the biggest side projects.

    Vercel and Netlify are great for static hosting and simple cloud functions. Access to the rest of AWS's ecosystem can be hard.

    Firebase I've used for experiments and it felt cumbersome. My brain doesn't work that way.

    Haven't found an excuse yet to try Azure :)

    How about operation like CI/CD on serverless?

    Continuous integration and deployment is where serverless shines!

    With infrastructure-as-code you define your whole app in your code. Frontend, backend, server, database, queues, everything. It's all there in your version control.

    That means every pull request, every branch, every feature, can have its own deploy with its own infrastructure and custom URLs. Run as many as you want in parallel 🤘

    You get a fantastic integration experience.

    Wanna automate the testing itself? Serverless is great at running code on demand ;)

    How to handle more complex Database queries where you would normally use an ORM and models? How to share those between functions?

    The JavaScript ecosystem for Object Relational Models (ORM) is kinda rough.

    Decent libraries exist from the Backbone era (circa 2012) but they feel weird in modern days. And it's hard to modernize when a lot of existing code depends on your library.

    TypeScript-based ORM approaches have cropped up in recent years and they look like small pet projects. You wouldn't wanna bet your company on those just yet.

    Prisma feels like the most serious play in this space right now. They've got a great SQL builder with fantastic TypeScript support. I haven't had a chance to try it yet.

    You can always use SQL directly. That always works :)

    As you can imagine this is why Mongo and DynamoDB are popular in the JavaScript world – save JSON objects, get JSON objects.

    Got more questions? Hit reply

    Cheers,
    ~Swizec

    PS: my new Serverless Handbook launches on Wednesday and if you buy this week will have a chance to win a signed copy

    Did you enjoy this article?

    Published on March 29th, 2021 in Serverless, Technical

    Want to dive into serverless? Not sure where to begin?

    Serverless Handbook was designed for people like you getting into backend programming.

    360 pages, 19 chapters, 6 full projects, hand-drawn diagrams, beautiful chapter art, best-looking cover in tech. ✌️

    Serverless Handbook on your bookshelf
    Serverless Handbook on your bookshelf

    Learn how to choose the right database, write cloud functions, think about scalability, gain the architecture mindsets for robust systems, and more.

    Leave your email to start with a free chapter and email crash course 👇

    Serverless Handbook for Frontend Engineers – free chapter

    Dive modern backend. Understand any backend.

    Serverless Handbook taught me high-leveled topics. I don't like recipe courses and these chapters helped me to feel like I'm not a total noob anymore.

    The hand-drawn diagrams and high-leveled descriptions gave me the feeling that I don't have any critical "knowledge gaps" anymore.

    ~ Marek C, engineer

    Start with a free chapter and email crash course ❤️

    Join over 14,000 engineers just like you already improving their careers with my letters, workshops, courses, and talks. ✌️

    Have a burning question that you think I can answer? I don't have all of the answers, but I have some! Hit me up on twitter or book a 30min ama for in-depth help.

    Ready to Stop copy pasting D3 examples and create data visualizations of your own?  Learn how to build scalable dataviz components your whole team can understand with React for Data Visualization

    Curious about Serverless and the modern backend? Check out Serverless Handbook, modern backend for the frontend engineer.

    Ready to learn how it all fits together and build a modern webapp from scratch? Learn how to launch a webapp and make your first 💰 on the side with ServerlessReact.Dev

    Want to brush up on your modern JavaScript syntax? Check out my interactive cheatsheet: es6cheatsheet.com

    By the way, just in case no one has told you it yet today: I love and appreciate you for who you are ❤️

    Created by Swizec with ❤️