Search code examples
amazon-web-servicesaws-lambdaserverless

Is AWS Lambda good for real-time API Rest?


I'm learning about AWS Lambda and I'm worried about synchronized real-time requests. The fact the lambda has a "cold start" it doesn't sounds good for handling GET petitions.

Imagine a user is using the application and do a GET HTTP Request to get a Product or a list of Products, if the lambda is sleeping, then it will take 10 seconds to respond, I don't see this as an acceptable response time. Is it good or bad practice to use AWS Lambda for classic (sync responses) API Rest?


Solution

  • Like most things, I think you should measure before deciding. A lot of AWS customers use Lambda as the back-end for their webapps quite successfully.

    There's a lot of discussion out there on Lambda latency, for example:

    In December 2019, AWS Lambda introduced Provisioned Concurrency, which improves things. See:

    You should measure latency for an environment that's representative of your app and its use.

    A few things that are important factors related to request latency:

    • cold starts => higher latency
    • request patterns are important factors in cold starts
    • if you need to deploy in VPC (attachment of ENI => higher cold start latency)
    • using CloudFront --> API Gateway --> Lambda (more layers => higher latency)
    • choice of programming language (Java likely highest cold-start latency, Go lowest)
    • size of Lambda environment (more RAM => more CPU => faster)
    • Lambda account and concurrency limits
    • pre-warming strategy

    Update 2019-12: see Predictable start-up times with Provisioned Concurrency.

    Update 2021-08: see Increasing performance of Java AWS Lambda functions using tiered compilation.