官术网_书友最值得收藏!

Models

In this chapter, we will discuss the following topics:

  • The importance of models
  • Class diagrams
  • Model structural patterns
  • Model behavioral patterns
  • Migrations

I was once consulted by a data analytics start-up in their early stages. Despite data retrieval being limited to a window of recent data, they had performance issues with page load sometimes taking several seconds. After analyzing their architecture, the problem seemed to be in their data model. However, migrating and transforming petabytes of structured live data seemed impossible.

"Show me your flowcharts and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won't usually need your flowcharts; they'll be obvious."

— Fred Brooks, The Mythical Man-month

Traditionally, designing code around well thought-out data is always recommended. But in this age of big data, that advice has become more relevant. If your data model is poorly designed, the volume of data will eventually cause scalability and maintenance issues. I recommend using the following adage on how to balance code and data:

Rule of Representation: Fold knowledge into data so program logic can be stupid and robust.

Think about how you can move the complexity from code to data. It is always harder to understand logic in code compared to data. UNIX has used this philosophy very successfully by giving many simple tools that can be piped to perform any kind of manipulation on textual data.

Finally, data has greater longevity than code. Enterprises might decide to rewrite entire codebases because they don't meet their needs anymore, but the databases are usually maintained and even shared across applications.

Well-designed databases are more of an art than a science. This chapter will give you some fundamental principles such as Normalization and best practices around organizing your data. But before that, let's look at where data models fit in a Django application.

主站蜘蛛池模板: 独山县| 隆子县| 临朐县| 冀州市| 吴江市| 尤溪县| 涪陵区| 阳朔县| 麟游县| 涞源县| 通辽市| 灵石县| 林芝县| 日土县| 蒲江县| 罗江县| 牙克石市| 那曲县| 怀化市| 昌吉市| 温泉县| 安吉县| 西和县| 霍林郭勒市| 安达市| 涞水县| 稻城县| 调兵山市| 岐山县| 昌江| 新郑市| 定边县| 吉木乃县| 西乌珠穆沁旗| 泾川县| 张家口市| 睢宁县| 微山县| 拜泉县| 武义县| 苏尼特左旗|