<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: amar goyal</title>
    <description>The latest articles on Forem by amar goyal (@amar_goyal_db05).</description>
    <link>https://forem.com/amar_goyal_db05</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3585394%2Fa8fe5bd2-0aca-46df-beb0-3500dd45f45e.jpg</url>
      <title>Forem: amar goyal</title>
      <link>https://forem.com/amar_goyal_db05</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/amar_goyal_db05"/>
    <language>en</language>
    <item>
      <title>Serverless Cold Start - Tips</title>
      <dc:creator>amar goyal</dc:creator>
      <pubDate>Tue, 28 Oct 2025 10:46:17 +0000</pubDate>
      <link>https://forem.com/amar_goyal_db05/serverless-cold-start-tips-4kbh</link>
      <guid>https://forem.com/amar_goyal_db05/serverless-cold-start-tips-4kbh</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Why does it matter?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Serverless platforms like AWS Lambda, Azure Functions, and Google Cloud Functions scale on demand—but they sometimes introduce cold starts, where functions experience latency due to initialization time, especially when idle or after deployment.&lt;br&gt;
This can negatively impact performance, especially for APIs or latency-sensitive applications.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Tips to Reduce Cold Starts&lt;/strong&gt;
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. Keep Functions Lightweight
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Only import what you need.&lt;/li&gt;
&lt;li&gt;Avoid loading large libraries (e.g., don't load all of AWS SDK if you only need S3) -refer below code
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @aws-sdk/client-s3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then in your code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
const s3 = new S3Client({ region: "us-east-1" });
await s3.send(new PutObjectCommand({
  Bucket: "my-bucket",
  Key: "example.txt",
  Body: "Hello world!"
}));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Result:
&lt;/h4&gt;

&lt;p&gt;i. Only the S3 client and its dependencies are loaded — not the entire AWS SDK.&lt;br&gt;
ii. This keeps your bundle small and avoids unnecessary code.&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Use Provisioned Concurrency (AWS Lambda)
&lt;/h3&gt;

&lt;p&gt;Keeps a set number of Lambda instances "warm" and ready to handle requests instantly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws lambda put-provisioned-concurrency-config \
  --function-name myFunction \
  --qualifier 1 \
  --provisioned-concurrent-executions 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Avoid VPC Unless Necessary
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Placing functions inside a VPC can increase cold start time due to ENI setup.&lt;/li&gt;
&lt;li&gt;Only attach VPC if needed (e.g., RDS or private subnets).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Choose the Right Runtime
&lt;/h3&gt;

&lt;p&gt;Lighter runtimes (e.g., Node.js, Python) usually have faster cold starts than JVM-based ones like Java or .NET.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Ping Functions Periodically (as a Last Resort)
&lt;/h3&gt;

&lt;p&gt;Use CloudWatch Events (or similar schedulers) to "keep warm" by invoking your function every 5–10 minutes.&lt;br&gt;
Note: This is a workaround and not as reliable as provisioned concurrency.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Takeaway&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Cold starts are an inherent trade-off with serverless—but with smart design and a few settings, you can reduce or eliminate their impact on user experience.&lt;/p&gt;

</description>
      <category>serverless</category>
      <category>aws</category>
      <category>azure</category>
      <category>gcp</category>
    </item>
  </channel>
</rss>
