今日已更新 344 条资讯 | 累计 37249 条内容
关于我们

Serverless: When It Helps and When It Hurts

Cloud Frontier 2026年08月21日 08:00 3 次阅读 来源:Dev.to

The Allure of Serverless Serverless computing, despite its name, still runs on servers. The difference is that you don't manage them. You deploy functions, and the cloud provider handles scaling, patching, and availability. The promise is simple: you focus on code, not infrastructure. That's genuinely appealing for many projects, but it's not a silver bullet. Let's talk about when serverless shines and when it becomes a headache. When Serverless Helps 1. Spiky and Unpredictable Traffic Serverless scales automatically. If you have a sudden surge of users, functions spin up to handle the load, then scale down to zero when idle. You pay only for what you use. This is ideal for APIs with variable traffic, like a mobile app backend that sees daily peaks and quiet nights. For example, a simple REST endpoint using AWS Lambda and API Gateway: exports . handler = async ( event ) => { const body = JSON . parse ( event . body ); // process request return { statusCode : 200 , headers : { ' Content-Type ' : ' application/json ' }, body : JSON . stringify ({ message : `Hello, ${ body . name } !` }) }; }; No server to configure, no load balancer to set up. It just works. 2. Event-Driven Workloads Serverless excels at reacting to events: file uploads, database changes, messages in a queue. You can glue services together with minimal code. For instance, resizing an image when it's uploaded to S3: import boto3 from PIL import Image import os s3 = boto3 . client ( ' s3 ' ) def handler ( event , context ): bucket = event [ ' Records ' ][ 0 ][ ' s3 ' ][ ' bucket ' ][ ' name ' ] key = event [ ' Records ' ][ 0 ][ ' s3 ' ][ ' object ' ][ ' key ' ] download_path = ' /tmp/ ' + key upload_path = ' /tmp/resized- ' + key s3 . download_file ( bucket , key , download_path ) with Image . open ( download_path ) as img : img . thumbnail (( 200 , 200 )) img . save ( upload_path ) s3 . upload_file ( upload_path , bucket , ' resized/ ' + key ) This is a perfect serverless use case: short-lived, statele

本文内容来源于互联网,版权归原作者所有
查看原文