TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Tips for Building High-Quality Django Apps at Scale

191 pointsby stanleytangabout 8 years ago

12 comments

randomsearchabout 8 years ago
I&#x27;m so glad to see the mention of &quot;app&quot; directories here. I&#x27;ve only dabbled in Django development, but I&#x27;ve always thought the desire to divide things into apps didn&#x27;t really make any sense. It felt like the developers of Django had said &quot;well, intuitively, there <i>must</i> be some unit of reuse at this level&quot; and then stuck the notion of apps in there in an attempt to provide that reuse.<p>This seems to me to be somewhat unpythonic, unnecessary complexity introduced right from the start - why not make the reuse optional?. The file system layout becomes confusing as a result. More generally, I would expect that the most minimal Django site would be a single file, that would seem most Pythonic, but it isn&#x27;t designed like that. Django doesn&#x27;t &quot;feel&quot; like most Python projects do.<p>I&#x27;ve always assumed this must be because I&#x27;m a total noob&#x2F;idiot when it comes to real-world development, and that projects like Django must be doing things right and I just don&#x27;t get it (although it remains entirely possible that this is the case).<p>It&#x27;s heartening, however, to see I&#x27;m at least not _entirely_ wrong for having a gut unease about this, and it makes me wonder how on earth I can judge whether it&#x27;s me or a given framework&#x2F;language in the general case.<p>Do I have reverse Dunning–Kruger? Or did I just guess right in this case? I have no idea.
评论 #14361109 未加载
评论 #14362196 未加载
评论 #14362057 未加载
评论 #14361280 未加载
评论 #14363776 未加载
评论 #14363400 未加载
评论 #14364477 未加载
评论 #14364419 未加载
评论 #14362590 未加载
cwisecarverabout 8 years ago
I&#x27;ve got more than 5 years of experience with Django on a number of teams and at a couple of companies and in my experience almost everything in this article is completely incorrect.<p>The only things I would agree with is the point about project layout and avoiding django&#x27;s squashmigrations for the truncate the migrations table, delete the migrations, and create a new initial migration.<p>Practically everything else in this article is wrong, in my opinion.
评论 #14361197 未加载
评论 #14361283 未加载
评论 #14361392 未加载
评论 #14361116 未加载
评论 #14362392 未加载
评论 #14364510 未加载
goblin89about 8 years ago
I find that the safest way to migrate DB schema is gradually, spreading out intermediate steps across a few deploys.<p>Migrate the schema creating the (initially unused) fields in advance. Step by step change your logic where it talks to the storage—start querying new field values with a fallback, use new fields for incoming data. Migrate the existing data. Remove the fallbacks. Ensure the old fields are not used at this point. Migrate the schema, finally deleting the old fields.<p>Don’t rush, let every step reach production. In deployment sequence, apply migrations after the new code is already running. Goes without saying, monitor error rates for spikes.<p>Yes, at some points in time your production DB schema won’t be fully normalized. In return for prolonged messiness you get smoother flow, no single fateful and stressful deployment that attempts to get it right all in one go.<p>Migration handling is the only part of the article I find a bit foggy and debatable. The rest roughly resonates with what I’ve arrived at through my years of experience with Django web apps.
Osmoseabout 8 years ago
I appreciate this article for talking about scale in terms of project size and cognitive overhead, instead of in terms of traffic&#x2F;computation&#x2F;storage. Writing maintainable services isn&#x27;t easy, and tips like these are painful to learn on your own.
johnthealy3about 8 years ago
I was feeling okay about this article until seeing this colossal punt:<p>&gt; That said, the real intention behind this pattern is to keep the API&#x2F;view&#x2F;controller lightweight and free of excessive logic, which is something we would strongly advocate. Having logic inside model methods is a lesser evil, but you may want to consider keeping models lightweight and focused on the data layer. To make this work, you will need to figure out a new pattern and put your business logic in some layer that is in between the data layer and the API&#x2F;presentational layer.<p>Having fat models is definitely a problem I&#x27;m having, and it&#x27;s nice to see it&#x27;s a problem for the author too, but the advice &quot;figure it out&quot; is presented without any explicit suggestions.
评论 #14361886 未加载
评论 #14361867 未加载
St-Clockabout 8 years ago
&quot;Don’t cache Django models&quot;<p>This is too broad to be good advice. A typical solution to stale models is to increment a cache version key, effectively invalidating the old cache.<p>Version keys can be coarse- or fine-grained. For example, you may have one version key for the entire application (supported by Django by default) and one version key per model or application (you have to roll your own solution). If your app&#x27;s models change, you can increment the app version key and the next time you try to fetch a model instance from the cache, you will miss and instead fetch the instance from the DB.
bradmwalkerabout 8 years ago
<a href="https:&#x2F;&#x2F;mobile.twitter.com&#x2F;HackerNewsOnion&#x2F;status&#x2F;476835980863733761" rel="nofollow">https:&#x2F;&#x2F;mobile.twitter.com&#x2F;HackerNewsOnion&#x2F;status&#x2F;4768359808...</a>
msmmabout 8 years ago
It seems like author has problems with correctly architecting his apps and blames Django for his inability to do that. Only thing that makes sense is a tip for migrations.
nezoabout 8 years ago
About ContentType : &quot;If you ever move models between apps or rename your apps, you’re going to have to do some manual patching on this table&quot;<p>Thanks for this, just had a kind of struggle recently
joepourabout 8 years ago
It&#x27;s interesting that they&#x27;re still using the default ORM. Stranger still they&#x27;re letting the ORM scaffold tables (?!?) now they&#x27;re at this size?
tinixabout 8 years ago
This reads way more like a list of Django caveats and anti-patterns, than a guide to running any kind of Python application at &quot;scale&quot;. Maybe a sprinkling of good hygiene, but that has nothing to do with scalability (unless you&#x27;re talking about developer scalability and cognitive overhead).<p>Further, to suggest NOT using the ORM and to build out a middle layer on top of the ORM just for CRUD, is, well, insanity. On one hand the author is saying to cut down on bloat, and then on the other hand they are saying to add needless abstraction on an already bloated ORM.<p>I don&#x27;t use Django, but I do use Python for application development nearly every day, and I have to say... this article reads more like a list of (predictable and basic) problems their team had than a guide to scaling an application. Maybe they mean, how to scale their team, workflow, and their efficiency, NOT the application itself.<p>The only thing I agree with here is the avoidance of some Django features... However, they should take it a step further, and just avoid Django in the first place.<p>Also, am I the only one that has never needed to use &quot;migrations&quot; or any similar sorts of features? You&#x27;re doing something very wrong and overcomplicating things if you seriously need to lean on migrations that heavily.
评论 #14361538 未加载
评论 #14361546 未加载
linkmotifabout 8 years ago
Django is not meant to be run at scale. At least not horizontal scale. If you&#x27;re not going to use the ORM, which prevents you from scaling horizontally, why are you using Django? Django can be scaled by getting large instances with lots of RAM, which is quite affordable these days. It can also be scaled with caching. But if you want horizontal scaling, don&#x27;t use Django. That&#x27;s not what it&#x27;s for.
评论 #14362754 未加载
评论 #14362627 未加载