Synchronous waiting within a single Lambda function
Within a single Lambda, ensure that any potentially concurrent activities are not scheduled synchronously. For example, a Lambda function might write to an S3 bucket and then write to a DynamoDB table:
![event driven architectures figure 17](/images/lambda/latest/operatorguide/images/event-driven-architectures-figure-17.png)
The wait states, shown in the red in the diagram, are compounded because the activities are sequential. If the tasks are independent, they can be run in parallel, which results in the total wait time being set by the longest-running task.
![event driven architectures figure 18](/images/lambda/latest/operatorguide/images/event-driven-architectures-figure-18.png)
In cases where the second task depends on the completion of the first task, you may be able to reduce the total waiting time and the cost of execution by splitting the Lambda functions:
![event driven architectures figure 19](/images/lambda/latest/operatorguide/images/event-driven-architectures-figure-19.png)
In this design, the first Lambda function responds immediately after putting the object to the S3 bucket. The S3 service invokes the second Lambda function, which then writes data to the DynamoDB table. This approach minimizes the total wait time in the Lambda function executions.
To learn more, read the Serverless Applications Lens