Serverless Simplified

Core Ideas, Key Considerations, and Practical Projects to Get You Building Fast.

Hi inner circle,

Today, we are exploring serverless computing.

We start with the core components you must know, followed by design considerations with serverless — so you can knock down those interviews; and lastly, I have shared a few projects with some free resources that you can use to upskill and add to your resume.

Let’s dive in!!

Core Terms You Should Know

Think of these as your starter kit of serverless vocabulary:

Serverless: This is the big one! It doesn't mean no servers, but rather that the cloud provider (like aws, gcp, azure or oci) handles all the server management for you. You just write your code, and they make sure it runs when needed. No more patching, scaling, or worrying about hardware!

Function as a Service (FaaS): This is the heart of serverless. You write small, single-purpose pieces of code (functions) that run in response to specific events. Think of it like a tiny robot that only wakes up to do one specific job when told, then goes back to sleep.

Event-Driven Architecture: This is how serverless applications typically work. Instead of constantly running servers waiting for requests, serverless functions are triggered by events. An event could be anything: a new file uploaded to storage, a user clicking a button on a website, a message arriving in a queue, or a scheduled time.

Invocation: This simply means a single execution of your serverless function. When an event happens and your function runs, that's one invocation.

Cold Start: Imagine your robot (function) has been sleeping for a while. The very first time it's woken up to do a job, it takes a little longer to "boot up" and get ready. That initial delay is called a "cold start." It's usually very quick (milliseconds to a few seconds), but it's something to be aware of for latency-sensitive applications.

Stateless: Most serverless functions are designed to be stateless. This means they don't "remember" anything from previous invocations. Each time your function runs, it's a fresh start. If you need to store data or remember things between invocations, you'll use external services like databases. This is key for easy scaling!

Scalability (Automatic Scaling): One of the biggest perks! Serverless platforms automatically scale your functions up or down based on demand. If you suddenly get a huge surge in users, your functions will magically spin up more instances to handle the load. When demand drops, they scale back down, saving you money.

Pay-per-Execution/Pay-per-Use: This is how you're billed. Instead of paying for servers that are running 24/7 (even when idle), you only pay for the compute time your functions actually consume. If your function runs for 200 milliseconds, you pay for 200 milliseconds. This can lead to significant cost savings, especially for infrequent workloads.

Designing Your Serverless Masterpiece: Considerations You’ll Be Tested on During Interviews

Building serverless isn't just about writing code; it's about thinking around when it’s used. Here are some key design considerations:

  • Event-Driven Thinking: Break your application down into smaller, independent functions that react to specific events.

  • Keep Functions Small and Focused (Single Responsibility): Each function should ideally do one thing and do it well.

  • Manage State Externally: Store persistent data outside your functions — think databases, object storage, or caching services.

  • Error Handling and Retries: Design your functions to gracefully handle failures with retries and dead-letter queues.

  • Security with Least Privilege: Give your functions only the permissions they need. Use secret managers instead of hardcoding sensitive data.

  • Monitoring and Logging: Good observability is critical in serverless. Implement logging and set up alerts for performance and errors.

  • Optimize for Cold Starts: Use lightweight runtimes, minimize package size, or configure provisioned concurrency if needed.

Cloud Services: Your Serverless Toolkit (AWS, Azure, GCP)

The three major cloud providers all offer robust serverless platforms. While the names might differ, the core concepts are very similar!

Amazon Web Services (AWS)

  • AWS Lambda: For FaaS use-case - this is where you run your code. It's event-driven and integrates with a vast array of other AWS services.

  • Amazon API Gateway: Your front door for exposing Lambda functions as HTTP APIs (think web applications or mobile backends). It handles routing, authentication, and more.

  • Amazon S3 (Simple Storage Service): Object storage, often used to trigger Lambda functions (e.g., image resizing when a new photo is uploaded).

  • Amazon DynamoDB: A fast, flexible NoSQL database that scales seamlessly and is a common choice for serverless applications due to its tight integration with Lambda.

  • AWS Step Functions: For orchestrating complex workflows involving multiple Lambda functions and other services.

  • Amazon SQS (Simple Queue Service): A message queuing service to decouple components and handle asynchronous processing.

Microsoft Azure

  • Azure Functions: Azure's FaaS offering, similar to AWS Lambda. Supports various languages and triggers.

  • Azure API Management: For exposing your Azure Functions (and other services) as APIs, providing capabilities like security, rate limiting, and analytics.

  • Azure Blob Storage: Azure's object storage service, which can trigger Azure Functions.

  • Azure Cosmos DB: Microsoft's globally distributed, multi-model NoSQL database, well-suited for serverless applications.

  • Azure Logic Apps: A visual workflow designer for orchestrating serverless workflows and integrating different services.

  • Azure Service Bus: A reliable message queuing and publish-subscribe service for decoupled communication.

Google Cloud Platform (GCP)

  • Google Cloud Run Functions: GCP's FaaS service. Event-driven and supports many popular programming languages.

  • Google Cloud Run: A powerful option that lets you run containerized applications in a fully managed serverless environment. Great if you want more control over your runtime while still enjoying serverless benefits. The difference from functions is in the deployment model.

  • Google Cloud Storage: GCP's object storage, frequently used to trigger Cloud Functions.

  • Google Cloud Firestore (or Datastore): A NoSQL document database that's highly scalable and integrates well with Cloud Functions.

  • Google Cloud Workflows: For orchestrating serverless workflows across various Google Cloud services.

  • Google Cloud Pub/Sub: A real-time messaging service for event ingestion and delivery.

Projects you can build to show your expertise in Serverless computing:

You're in luck! There are tons of great serverless projects with tutorials across all major cloud providers. Here are a few solid project ideas, each with resources for AWS, Azure, and GCP, designed to get you hands-on without being overwhelming:

1. Serverless Image Resizer

This is a classic "Hello World" of serverless, perfectly illustrating event-driven architecture. When an image is uploaded to cloud storage, a serverless function automatically resizes it to various dimensions and saves the new versions.

Tutorials/Labs/GitHub:

2. Simple URL Shortener

Build an API that takes a long URL and returns a short, unique one. When the short URL is accessed, it redirects to the original. This introduces API Gateways and database interactions.

Tutorials/Labs/GitHub:

3. Scheduled Data Cleanup/Processing

Automate routine tasks like deleting old temporary files from storage, moving data between databases, or generating daily reports. A serverless function runs on a schedule.

Tutorials/Labs/GitHub:

4. Simple Real-time Chat Application (WebSockets)

This is a more advanced project, but incredibly rewarding for understanding real-time serverless. Users can send messages to each other in a chat room, with messages being instantly delivered.

Tutorials/Labs/GitHub:

Serverless is an exciting paradigm shift that lets you focus on building features rather than babysitting infrastructure. Whether you’re preparing for interviews or just want to modernize your skillset, understanding serverless concepts and building projects like these will put you ahead of the curve.

Stay curious, keep building, and don’t forget: every line of code you write in serverless is a step toward becoming the engineer you want to be!

Until next time, happy learning (and applying)!

Daily News for Curious Minds

Be the smartest person in the room by reading 1440! Dive into 1440, where 4 million Americans find their daily, fact-based news fix. We navigate through 100+ sources to deliver a comprehensive roundup from every corner of the internet – politics, global events, business, and culture, all in a quick, 5-minute newsletter. It's completely free and devoid of bias or political influence, ensuring you get the facts straight. Subscribe to 1440 today.