<?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>DEV Community: Jay Z</title>
    <description>The latest articles on DEV Community by Jay Z (@astrozzc).</description>
    <link>https://dev.to/astrozzc</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%2F668370%2F4e4a64e3-d8d3-4022-854e-d57f70551991.jpeg</url>
      <title>DEV Community: Jay Z</title>
      <link>https://dev.to/astrozzc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/astrozzc"/>
    <language>en</language>
    <item>
      <title>Django: Don't put default sorting in the model</title>
      <dc:creator>Jay Z</dc:creator>
      <pubDate>Fri, 25 Jul 2025 19:42:59 +0000</pubDate>
      <link>https://dev.to/astrozzc/django-dont-put-default-sorting-in-the-model-4gj5</link>
      <guid>https://dev.to/astrozzc/django-dont-put-default-sorting-in-the-model-4gj5</guid>
      <description>&lt;p&gt;Or you will get stuck in the query for objects once the number of records become large. Even with return limit such as .first() it would take forever to run&lt;/p&gt;

</description>
      <category>django</category>
      <category>performance</category>
      <category>database</category>
    </item>
    <item>
      <title>Caution with try/expect when during with concurrent requests</title>
      <dc:creator>Jay Z</dc:creator>
      <pubDate>Mon, 09 May 2022 20:25:41 +0000</pubDate>
      <link>https://dev.to/astrozzc/caution-with-tryexpect-when-during-with-concurrent-requests-pij</link>
      <guid>https://dev.to/astrozzc/caution-with-tryexpect-when-during-with-concurrent-requests-pij</guid>
      <description>&lt;p&gt;Look at this code:&lt;br&gt;
&lt;code&gt;try&lt;br&gt;
    example.objects.get(name=xxx)&lt;br&gt;
 expect Exception:&lt;br&gt;
    example.objects.create(name=xxx)&lt;br&gt;
    blah, blah&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
The code seems to be working, but it is not thread safe. When we have concurrent requests coming to the server. The requests would penetrate into the expect block and try to create the resource or do something, causing unexpected behavior.&lt;/p&gt;

</description>
      <category>django</category>
      <category>concurrent</category>
    </item>
    <item>
      <title>Kafka not working in Gunicorn+Django</title>
      <dc:creator>Jay Z</dc:creator>
      <pubDate>Mon, 09 May 2022 20:19:21 +0000</pubDate>
      <link>https://dev.to/astrozzc/kafka-not-working-in-gunicorndjango-10b3</link>
      <guid>https://dev.to/astrozzc/kafka-not-working-in-gunicorndjango-10b3</guid>
      <description>&lt;p&gt;We are integrating kafka into our Django server. The messages never got send out, although the "send" method of the kafka producer is called.&lt;/p&gt;

&lt;p&gt;Finally found the root cause, which is due to the gunicorn. The kafka producer instance is initiated with some threads in it during the server start, in the main process. Later the gunicorn fork the instance into workers, but not the threads. So there will be empty threads for the kafka producer in workers.&lt;/p&gt;

&lt;p&gt;How to solve it? We don't want to initiate that kafka producer for each send request, which is a waste of time. So we made a lazy instantiation to get the kafka producer: if it does exist, instantiate one, and set it for our kafka producer instance; if it exist(must be instantiated by last send message call), return the kafka producer.&lt;/p&gt;

</description>
      <category>django</category>
      <category>gunicorn</category>
      <category>kafka</category>
    </item>
  </channel>
</rss>
