<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sarwan Ahmed on Medium]]></title>
        <description><![CDATA[Stories by Sarwan Ahmed on Medium]]></description>
        <link>https://medium.com/@shaikhsarwan49?source=rss-e49711098a42------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mwXQ_FFUMHHY5hxc4LIOMw.jpeg</url>
            <title>Stories by Sarwan Ahmed on Medium</title>
            <link>https://medium.com/@shaikhsarwan49?source=rss-e49711098a42------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 10:31:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shaikhsarwan49/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Signed URLs in AWS, GCP, and Azure: A Beginner-Friendly Guide]]></title>
            <link>https://medium.com/@shaikhsarwan49/signed-urls-in-aws-gcp-and-azure-a-beginner-friendly-guide-e2e549425865?source=rss-e49711098a42------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2e549425865</guid>
            <category><![CDATA[sastoken]]></category>
            <category><![CDATA[signed-urls]]></category>
            <category><![CDATA[s3-pre-signed-url]]></category>
            <dc:creator><![CDATA[Sarwan Ahmed]]></dc:creator>
            <pubDate>Mon, 29 Sep 2025 18:33:42 GMT</pubDate>
            <atom:updated>2025-09-29T18:33:42.192Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CgCP_ww1VU8oUaG6RDRycw.png" /></figure><h3>📝 Introduction</h3><p>Have you ever needed to share a file from cloud storage without making it completely public? Maybe you wanted to let a user download a report, but only for a few minutes, and without exposing your entire bucket or container. That’s exactly where <strong>signed URLs</strong> (also called <em>presigned URLs</em> or <em>shared access signatures</em>) come in.</p><p>In this blog, we’ll explore how <strong>AWS, Google Cloud, and Azure</strong> handle signed URLs, why they matter, what roles/permissions are required, and how you can generate them with code examples.</p><h3>🎯 Problem / Context</h3><p>Storing files in cloud storage is easy. The challenge is <strong>secure access</strong>.</p><ul><li>If you make files <em>public</em>, anyone with the link can access them — bad for sensitive data.</li><li>If you make files <em>private</em>, only authorized apps can access them — but sharing gets complicated.</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F17FxSFyYNOgThnonDK%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExdWM3ZXA3aXZtNGw3NnNodmhjYjVqNDVycGYxcmYybW9pdGYzc3pkNiZlcD12MV9naWZzX3NlYXJjaCZjdD1n%2F17FxSFyYNOgThnonDK%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExdTc1cXB0Mnh4cW9vNGlrdHg0YzFoMWo4bTYyNzdjOXJvOHRkNjc5NyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F17FxSFyYNOgThnonDK%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7e299ff27c59b9c636b015f0c276522/href">https://medium.com/media/b7e299ff27c59b9c636b015f0c276522/href</a></iframe><p>Signed URLs solve this by creating a <strong>temporary link</strong> that grants secure access for a limited time. You decide: <em>who gets access, for how long, and what operations they can perform</em>.</p><h3>💡 Key Concepts</h3><ul><li><strong>Signed URL / Presigned URL</strong>: A URL that contains a cryptographic signature. It temporarily grants access to a specific file in cloud storage.</li><li><strong>Expiration Time</strong>: How long the signed URL remains valid (e.g., 5 minutes, 1 hour, up to 7 days).</li><li><strong>Permissions</strong>: Defines what the user can do — download, upload, delete, or list.</li><li><strong>Use Cases</strong>: Sharing downloads, temporary uploads, granting access without exposing credentials.</li></ul><p>Here’s the <strong>general flow of signed URLs</strong> across cloud providers:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0el4iAiG4lvjTyKaNwlxCw.png" /></figure><h3>🛠 How Signed URLs Work in AWS, GCP, and Azure</h3><p>Let’s walk through each cloud provider, step by step.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FBBBx74mQ4a5sQoZydk%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExY29qNDVld2RvaDAxZ3cxOTZvNTA0ZzFuMGQyaHRja2dlcWlyYzMwbCZlcD12MV9naWZzX3NlYXJjaCZjdD1n%2FBBBx74mQ4a5sQoZydk%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExamZqaWN5bWp3eTNlcXZyMjh5NGFzd2QxOXhhYm9rMjNhMjMxaDl1cCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FBBBx74mQ4a5sQoZydk%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="405" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6fa910a2c3c047f06d1c06722e31f91/href">https://medium.com/media/f6fa910a2c3c047f06d1c06722e31f91/href</a></iframe><p><strong>🔹 AWS S3: Presigned URLs</strong></p><p>In AWS, you can generate <strong>presigned URLs</strong> using the SDK. These URLs allow GET (download) or PUT (upload) operations on S3 objects.</p><p><strong>Required Role/Permissions:</strong></p><ul><li>s3:GetObject → for read access</li><li>s3:PutObject → for upload access</li><li>Must be attached to an IAM User or IAM Role</li></ul><p><strong>Expiry Time:</strong></p><ul><li>Maximum of <strong>7 days</strong></li></ul><p>With AWS Assume role:</p><pre>import boto3<br>from botocore.exceptions import NoCredentialsError<br>import datetime<br><br>sts_client = boto3.client(&quot;sts&quot;)<br>assumed_role = sts_client.assume_role(<br>    RoleArn=&quot;&lt;aws-assume-role&gt;&quot;, RoleSessionName=&quot;&lt;aws-assume-role-session&gt;&quot;<br>)<br>credentials = assumed_role.get(&quot;Credentials&quot;, {})<br># Create S3 Client<br>s3_client = boto3.client(<br>    &quot;s3&quot;,<br>    aws_access_key_id=credentials.get(&quot;AccessKeyId&quot;),<br>    aws_secret_access_key=credentials.get(&quot;SecretAccessKey&quot;),<br>    aws_session_token=credentials.get(&quot;SessionToken&quot;),<br>    region_name==&quot;&lt;s3-bucket-region&gt;&quot;,  # Important to set a correct region<br>)<br><br># Generate a pre-signed URL for downloading<br>url = s3_client.generate_presigned_url(https://medium.com/%3Cbr%3E%20%20%20%20ClientMethod=&#39;get_object&#39;,%3Cbr%3E%20%20%20%20Params={&#39;Bucket&#39;:%20&#39;&lt;bucket-name&gt;&#39;,%20&#39;Key&#39;:%20&#39;&lt;object-key-of-s3-file&gt;&#39;},%3Cbr%3E%20%20%20%20ExpiresIn=300%20%20#%205%20minutes%3Cbr%3E)<br><br>print(&quot;AWS Presigned URL:&quot;, url)</pre><p>With AWS Access keys:</p><pre>import boto3<br>from botocore.exceptions import NoCredentialsError<br>import datetime<br><br># Create S3 Client<br>s3_client = boto3.client(<br>    &quot;s3&quot;,<br>    aws_access_key_id=&quot;&lt;access-key-id&gt;&quot;,<br>    aws_secret_access_key=&quot;&lt;secret-access-key&gt;&quot;,<br>    region_name==&quot;&lt;s3-bucket-region&gt;&quot;,  # Important to set a correct region<br>)<br><br># Generate a pre-signed URL for downloading<br>url = s3_client.generate_presigned_url(https://medium.com/%3Cbr%3E%20%20%20%20ClientMethod=&#39;get_object&#39;,%3Cbr%3E%20%20%20%20Params={&#39;Bucket&#39;:%20&#39;&lt;bucket-name&gt;&#39;,%20&#39;Key&#39;:%20&#39;&lt;object-key-of-s3-file&gt;&#39;},%3Cbr%3E%20%20%20%20ExpiresIn=300%20%20#%205%20minutes%3Cbr%3E)<br><br>print(&quot;AWS Presigned URL:&quot;, url)</pre><p><strong>🔹 Google Cloud Storage: Signed URLs</strong></p><p>In GCP, signed URLs (also called <em>query string authentication</em>) can be generated with service account credentials.</p><p><strong>Required Role/Permissions:</strong></p><ul><li>roles/storage.objectViewer → for downloads</li><li>roles/storage.objectCreator → for uploads</li></ul><p><strong>Expiry Time:</strong></p><ul><li>Maximum of <strong>7 days (V4 signed URLs)</strong></li><li>Older <strong>V2 signed URLs</strong> allow longer expiration (even years), but V2 is deprecated and not recommended for new apps.</li></ul><pre>from datetime import timedelta<br>from google.cloud import storage<br>from google.auth import impersonated_credentials<br><br># Get default creds (from metadata server in GCP)<br>creds, _ = google.auth.default()<br><br># Impersonate your signer service account<br>impersonated_creds = impersonated_credentials.Credentials(<br>    source_credentials=creds,<br>    target_principal=&quot;&lt;service-account-email&gt;&quot;,<br>    target_scopes=[&quot;https://www.googleapis.com/auth/cloud-platform&quot;],<br>)<br><br>client = storage.Client(credentials=impersonated_creds)<br>bucket = client.bucket(&quot;&lt;gcp-bucket-name&gt;&quot;)<br>blob = bucket.blob(&quot;&lt;object-key-of-file&gt;&quot;)<br><br>url = blob.generate_signed_url(https://medium.com/%3Cbr%3E%20%20%20%20version=&quot;v4&quot;,%3Cbr%3E%20%20%20%20expiration=timedelta(minutes=5),<br>    method=&quot;GET&quot;<br>)<br><br>print(&quot;GCP Signed URL:&quot;, url)</pre><p><strong>🔹 Azure Blob Storage: Shared Access Signatures (SAS)</strong></p><p>Azure’s equivalent is the <strong>Shared Access Signature (SAS)</strong>. You can generate SAS tokens for containers, blobs, or even queues.</p><p><strong>Required Role/Permissions:</strong></p><ul><li>Storage Account Key <strong>or</strong> Azure AD Role:</li><li>Storage Blob Data Reader → read</li><li>Storage Blob Data Contributor → write/upload</li></ul><p><strong>Expiry Time:</strong></p><ul><li>When using a <strong>Account Key–based SAS, t</strong>here is <strong>no enforced maximum</strong> by Azure but best practice is to keep SAS tokens <strong>short-lived (minutes to hours)</strong> and regenerate them if needed.</li><li>When using a <strong>user delegation key (</strong>Azure AD Role<strong>)</strong>, the validity is limited by the user delegation key’s lifetime which only last <strong>a maximum of 7 days</strong>. So, the SAS token signed with it cannot extend beyond that.</li></ul><pre>from azure.storage.blob import generate_blob_sas, BlobSasPermissions<br>from datetime import datetime, timedelta<br><br>sas_token = generate_blob_sas(<br>    account_name=&quot;&lt;azure-account-name&gt;&quot;,<br>    container_name=&quot;&lt;azure-container-name&gt;&quot;,<br>    blob_name=&quot;&lt;file-name&gt;&quot;,<br>    account_key=&quot;&lt;account-key&gt;&quot;,<br>    permission=BlobSasPermissions(read=True),<br>    expiry=datetime.utcnow() + timedelta(seconds=300) # 5 minutes validity<br>)<br><br>url = f&quot;https://myaccount.blob.core.windows.net/&lt;container-name&gt;/&lt;file-name&gt;?{sas_token}&quot;<br><br>print(&quot;Azure SAS URL:&quot;, url)</pre><blockquote><em>Note this requires </em><strong><em>12.x SDK</em></strong><em> of azure.storage.blob</em></blockquote><h3>📊 Cloud Provider Comparison</h3><p>Here’s a side-by-side comparison:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6cSlG80fpOGrs5fihwqZnw.png" /></figure><p>And here’s how permissions work visually:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QbQQdk0YEBqWEHr6458ifw.png" /></figure><h3>✅ Key Takeaways</h3><ul><li><strong>AWS Presigned URLs</strong>: Simple, widely used, tied to IAM credentials.</li><li><strong>GCP Signed URLs</strong>: Require service accounts, support advanced HTTP methods.</li><li><strong>Azure SAS Tokens</strong>: Very granular, can apply to containers, blobs, or even entire services.</li></ul><p>All three providers give you time-limited, secure file access — but each uses slightly different terminology, roles, and APIs.</p><h3>🎯 Conclusion</h3><p>Signed URLs are one of those cloud features that feel like magic once you start using them. They let you share files securely, without exposing credentials or leaving storage wide open.</p><p>Whether you’re building a file upload service, sharing invoices, or enabling temporary downloads, <strong>AWS, GCP, and Azure all provide reliable tools</strong> — you just need to pick the right syntax and roles.</p><p>Have you used signed URLs in your projects? Which cloud provider’s approach do you prefer? Share your experience in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2e549425865" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deepcopy, a memory killer]]></title>
            <link>https://medium.com/@shaikhsarwan49/deepcopy-a-memory-killer-ca7bfabfbecb?source=rss-e49711098a42------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca7bfabfbecb</guid>
            <dc:creator><![CDATA[Sarwan Ahmed]]></dc:creator>
            <pubDate>Thu, 28 Nov 2024 17:19:39 GMT</pubDate>
            <atom:updated>2024-12-03T07:06:27.297Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jniX6zJbzg4YRimp" /></figure><h3>Context</h3><p>Recently during load-testing we faced a memory issue due to which Gunicorn workers were getting restarted when reaching memory limit.</p><p>The API which was causing the memory issue is written in django framework, inside this API a function named <em>create_hosts_and_devices_policy_rules_payload()</em> is being called which creates nested dictionaries. To avoid mutation issue, deepcopy() was being used inside for loop to create a new dictionary object.</p><p>The dictionary contains devices data and inside that each device contains nested data of rules, peers_details, app_details, saas_app_details and rule_details. The data looks like this.</p><pre>{<br>    &quot;device_id_1&quot;: {<br>        &quot;id&quot;: &quot;device_id_1&quot;,<br>        &quot;rules&quot;: [<br>            {<br>            &quot;id&quot;: &quot;rule_id_1&quot;,<br>            &quot;peers&quot;: [ &quot;host_id_1&quot;, &quot;host_id_2&quot;, ... ],<br>            &quot;applications&quot;: [ &quot;app_id_1&quot;, &quot;app_id_2&quot;, ... ],<br>            &quot;saas_applications&quot;: [&quot;saas_app_id_1&quot;, &quot;saas_app_id_2&quot;, ...]<br>            },<br>            ...<br>        ],<br>        &quot;peers_details&quot;: {<br>            &quot;host_id_1&quot;: {<br>                ...<br>            },<br>            ...<br>        },<br>        &quot;applications_details&quot;: {<br>            &quot;app_id_1&quot;: {<br>                ...<br>                },<br>            ...<br>        },<br>        &quot;rule_details&quot;: {<br>            &quot;rule_id_1&quot;: {<br>               ...<br>                },<br>            ...<br>        },<br>        &quot;saas_app_details&quot;: {<br>            &quot;saas_app_id_1&quot;: {<br>                ...<br>                },<br>        }<br>    },<br>    ...<br>}</pre><p>The issue was faced when this data was being created for 5000 devices and 300 applications (which is not a big number). The memory of pods were increased to around 3 GBs from 450 MBs.</p><h3>Debugging</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FbVJmilgAPW43cdpniz%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fquixyofficial-code-coding-debugging-bVJmilgAPW43cdpniz&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExd3M4c3JnNmF6a3gyb3pvNHd6dTV6NTFmeDc0dzR4OWE0b2xyZHp0MiZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FbVJmilgAPW43cdpniz%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="246" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e8e5716f157d9193239745ef2bd4707/href">https://medium.com/media/6e8e5716f157d9193239745ef2bd4707/href</a></iframe><p>Lets dive into how we found the issue using python’s memory_profiler</p><p>Step 1: Install memory_profiler</p><pre>pip install memory_profiler</pre><p>Step 2: Import profile from memory_profiler and add decorator on method which needs to be profiled</p><pre>from memory_profiler import profile<br>.<br>.<br>.<br>@profile<br>def create_hosts_and_devices_policy_rules_payload(<br>    devices_objects, access_groups_user_ids, results, rule_objects, event_type<br>):<br>...</pre><p>Step 3: Start django server using following command with <em>memory_profiler </em>option</p><pre>python manage.py -m memory_profiler runserver</pre><p>Step 4: Hit the API, the profiling results will be logged in console on completion of API request. Following are the profiling results of function <em>create_hosts_and_devices_policy_rules_payload()</em></p><pre>   Line #    Mem usage    Increment  Occurrences   Line Contents<br>=============================================================<br>   192    251.0 MiB    251.0 MiB           1   @profile<br>   193                                         def create_hosts_and_devices_policy_rules_payload(<br>   194                                             devices_objects, access_groups_user_ids, results, rule_objects, event_type<br>   195                                         ):<br>    .<br>    .<br>    .<br>   313    262.4 MiB     11.4 MiB           1       if len(results) &gt; 0 and devices_objects:<br>    .<br>    .<br>    .<br>   800                                                 # loop through devices to create device policies payload<br>   801                                                 # by replicating user policies payload to user&#39;s devices<br>   802    263.3 MiB      0.0 MiB           1           if event_type == EventTypes.ADD_RULE:<br>   803   1288.8 MiB      0.7 MiB        4967               for device_obj in devices_objects:<br>   804   1288.5 MiB      0.9 MiB        4966                   device_id = str(device_obj.id)<br>   805   1288.8 MiB   1000.2 MiB        4966                   copy_of_user_payload = deepcopy(user_rules_payload.get(str(device_obj.created_by_id), {}))<br>    .<br>    .<br>    .<br>   863   1288.8 MiB      0.0 MiB           1       return payload_for_host, payload_for_devices</pre><p>From above results we can see that there is a huge increase in memory on line number 805 where we are copying nested objects using deepcopy, this results in increasing memory significantly which leads to restarting of Gunicorn workers inside pods due to memory limit reached.</p><h3><strong>Resolution</strong></h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F453QsWPQj5bsQaqp8M%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Freaction-453QsWPQj5bsQaqp8M&amp;image=https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExcmp0Mnc0Nno2bnY0YTA0cm9oM2pyMTluYWRha3dxNGFvZWx4bnpsdyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F453QsWPQj5bsQaqp8M%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/d75fe7e0e0ea055a45a27bec2adb7be8/href">https://medium.com/media/d75fe7e0e0ea055a45a27bec2adb7be8/href</a></iframe><p>Deepcopy() was being used to avoid mutation issue but whole nested object was not mutable. We updated the code and used deepcopy() on those parts which are mutable and copied remaining parts as it (by reference).</p><p>Updated code:</p><pre># loop through devices to create device policies payload<br># by replicating user policies payload to user&#39;s devices<br>for device_obj in devices_objects:<br>    device_id = str(device_obj.id)<br>    user_payload = user_rules_payload.get(str(device_obj.created_by_id), {})<br>    device_rules_payload = {<br>        &quot;rules&quot;: deepcopy(user_payload.get(&quot;rules&quot;, [])),  # Deepcopy mutable parts only<br>        &quot;peers_details&quot;: user_payload.get(&quot;peers_details&quot;, {}),<br>        &quot;app_details&quot;: user_payload.get(&quot;app_details&quot;, {}),<br>        &quot;saas_app_details&quot;: user_payload.get(&quot;saas_app_details&quot;, {}),<br>        &quot;rule_details&quot;: deepcopy(user_payload.get(&quot;rule_details&quot;, {})),  # Deepcopy mutable parts only<br>        &quot;id&quot;: device_id,<br>    }</pre><p>Here are the profiling results after removing deepcopy() from nested objects</p><pre>Line #    Mem usage    Increment  Occurrences   Line Contents<br>=============================================================<br>   192    250.3 MiB    250.3 MiB           1   @profile<br>   193                                         def create_hosts_and_devices_policy_rules_payload(<br>   194                                             devices_objects, access_groups_user_ids, results, rule_objects, event_type<br>   195                                         ):<br>    .<br>    .<br>    .<br>   313    261.7 MiB     11.4 MiB           1       if len(results) &gt; 0 and devices_objects:<br>    .<br>    .<br>    .   <br>   800                                                 # loop through devices to create device policies payload<br>   801                                                 # by replicating user policies payload to user&#39;s devices<br>   802    261.7 MiB      0.0 MiB           1           if event_type == EventTypes.ADD_RULE:<br>   803    266.8 MiB      0.0 MiB        4967               for device_obj in devices_objects:<br>   804    266.8 MiB      0.8 MiB        4966                   device_id = str(device_obj.id)<br>   805                                                         # copy_of_user_payload = deepcopy(user_rules_payload)<br>   806    266.8 MiB      0.0 MiB        4966                   user_payload = user_rules_payload.get(str(device_obj.created_by_id), {})<br>   807    266.8 MiB      0.3 MiB        4966                   device_rules_payload = {<br>   808    266.8 MiB      0.0 MiB        4966                       &quot;rules&quot;: user_payload.get(&quot;rules&quot;, [])[:],  # Copy mutable parts only<br>   809    266.8 MiB      0.0 MiB        4966                       &quot;peers_details&quot;: user_payload.get(&quot;peers_details&quot;, {}),<br>   810    266.8 MiB      0.0 MiB        4966                       &quot;service_details&quot;: user_payload.get(&quot;service_details&quot;, {}),<br>   811    266.8 MiB      0.0 MiB        4966                       &quot;saas_services_details&quot;: user_payload.get(&quot;saas_services_details&quot;, {}),<br>   812    266.8 MiB      2.3 MiB        4966                       &quot;rule_details&quot;: deepcopy(user_payload.get(&quot;rule_details&quot;, {})),<br>   813    266.8 MiB      0.0 MiB        4966                       &quot;id&quot;: device_id,<br>   814    266.8 MiB      0.0 MiB        4966                       &quot;workspace_id&quot;: device_obj.workspace_id,<br>   815                                                         }<br>    .<br>    .<br>    .<br>   863    266.8 MiB      0.0 MiB           1       return payload_for_host, payload_for_devices</pre><p>We can see the difference of around 1 GB between previous and new results. This decrease in memory improved the performance significantly.</p><h3>Summary</h3><ul><li>Use simple copy() instead of deepcopy()</li><li>Avoid using deepcopy() on whole nested objects. Try to divide in chunks and use it where necessary</li><li>Load test your code and Profile it with large payload earlier to avoid facing issues later</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca7bfabfbecb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Crucial Role of Logs in Applications: A Deep Dive]]></title>
            <link>https://medium.com/@shaikhsarwan49/the-crucial-role-of-logs-in-applications-a-deep-dive-41f3641e0358?source=rss-e49711098a42------2</link>
            <guid isPermaLink="false">https://medium.com/p/41f3641e0358</guid>
            <dc:creator><![CDATA[Sarwan Ahmed]]></dc:creator>
            <pubDate>Sun, 27 Aug 2023 08:39:28 GMT</pubDate>
            <atom:updated>2023-08-27T08:39:28.512Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QM4AIEtMb0Z9Wj2TqLV1Tw.jpeg" /></figure><p>In the fast-paced world of software development, where efficiency and reliability are paramount, incorporating robust logging mechanisms might seem like an afterthought. However, the truth couldn’t be further from that. Logging is not just a mundane task to be checked off the development checklist; it’s a cornerstone of building dependable and maintainable applications. In this blog, we’ll explore the importance of adding logs in applications and shed light on the myriad of benefits they bring to the table.</p><h3>1. Understanding Logging: A Brief Overview</h3><p>At its core, logging involves capturing and storing information about the events and actions within an application. This information is then used for debugging, monitoring, and auditing purposes. Logs are like the breadcrumbs that developers can follow to trace the steps an application took and gain insights into its behavior under various conditions.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3ohhwfL19q2eCPaBEs%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3ohhwfL19q2eCPaBEs%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F3ohhwfL19q2eCPaBEs%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/d57de67625c7da6f742326e2e938b5f3/href">https://medium.com/media/d57de67625c7da6f742326e2e938b5f3/href</a></iframe><h3>2. The Importance of Logging</h3><h4>a. Debugging and Troubleshooting</h4><p>When issues arise, whether they’re minor bugs or critical failures, logs act as a lifeline for developers. They provide a detailed record of the application’s activities leading up to the problem, aiding in pinpointing the root cause. Without logs, developers might be left in the dark, struggling to recreate the scenario that led to the issue.</p><h4>b. Monitoring and Performance Optimization</h4><p>Logs offer real-time visibility into an application’s performance, helping teams to identify bottlenecks, slow operations, and resource utilization. By analyzing logs, developers can fine-tune the application for optimal performance, leading to a smoother user experience.</p><h4>c. Auditing and Compliance</h4><p>In applications that deal with sensitive data or have regulatory requirements, logs serve as an essential tool for auditing and compliance. They record user interactions, transactions, and system events, enabling organizations to prove compliance with industry standards and regulations.</p><h4>d. Documentation and Communication</h4><p>Logs can also function as a form of documentation. When a developer revisits their own code or when a new team member joins the project, well-structured logs can provide insights into the application’s flow and logic, expediting the on-boarding process.</p><h3>3. Best Practices for Effective Logging</h3><h4>a. Clear and Informative Messages</h4><p>Craft log messages that are concise, informative, and context-rich. Include relevant data such as timestamps, user IDs, error codes, and other pertinent details that can assist in diagnosing issues.</p><h4>b. Logging Levels</h4><p>Utilize different logging levels (e.g., DEBUG, INFO, WARN, ERROR) to differentiate between the severity of events. This allows developers to filter logs based on the importance of the information they provide.</p><h4>c. Structured Logging</h4><p>Implement structured logging formats such as JSON or key-value pairs. Structured logs are easier to parse, analyze, and correlate across various components of a complex system.</p><h4>d. Centralized Logging</h4><p>In distributed systems, centralizing logs from multiple sources simplifies monitoring and troubleshooting. Tools like Elasticsearch, Logstash, and Kibana (ELK stack) can help aggregate and analyze logs effectively.</p><h4>e. Regular Log Review</h4><p>Make log analysis a routine task. Regularly review logs to catch potential issues before they escalate and to ensure the application is running smoothly.</p><h3>4. Conclusion</h3><p>Logging might not be the most glamorous aspect of software development, but its significance cannot be overstated. It’s the safety net that rescues developers from the abyss of uncertainty when things go wrong. From debugging to compliance, optimization to documentation, logs play a pivotal role in shaping the reliability and maintainability of applications. By adhering to best practices and making logging an integral part of the development process, you’re investing in a more robust, efficient, and trustworthy application. So, embrace the logs and watch your applications shine even brighter in the ever-evolving digital landscape.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41f3641e0358" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>