技术控

    今日:136| 主题:49552
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] Data denormalization is broken

[复制链接]
鸭梨 发表于 2016-10-1 01:22:09
197 2

立即注册CoLaBug.com会员,免费获得投稿人的专业资料,享用更多功能,玩转个人品牌!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
Backend engineers can’t write elegant and performant application-layer code for many types of everyday business logic. That’s because no one has yet invented a “denormalization engine”, a database with a more general kind of indexer.
  To see what I mean, let’s dive into an example application and talk about its data architecture: how it works today vs. how we’d ideally want it to work.
  Example: A messaging application

  Say we want to build a messaging application with various conversation “rooms”. Basically a clone of Facebook Messenger, which has one room per person you’re chatting with:
         
Data denormalization is broken-1 (Facebook,invented,business,database,message)
         Facebook Messenger clone showing 7 rooms (2 unread, 5 read)      Notice that in this screenshot, there are two unread rooms. We’ll define an unread room (with respect to the current logged-in user) as “a room whose last message’s timestamp is greater than the timestamp when the current user last viewed it”.
  Naturally, we want to be able to render a UI like this:

Data denormalization is broken-2 (Facebook,invented,business,database,message)
         Hm, where did this “2” come from?      How do we architect the calculation of the number of unread rooms? It seems like a straightforward problem, an example of what I mean by “everyday business logic”.
   We’ll consider two architectural approaches for counting unread rooms: the normalized approach and the denormalized approach.
  The normalized approach

   When building an application, there’s always a core schema of data types and fields that we absolutely need in our database. That’s the normalized schema for our application.
  Designing a normalized schema is largely product-definition work, not engineering implementation work. That’s because the set of possible values for the data in a normalized schema corresponds to the set of possible states that your application can meaningfully be in.
  Roughly, the space of possible data values that constitute valid entries into your normalized schema, is supposed to represent the space of meaningful states that your application can be in. Good programmers put a lot of thought into designing their application’s normalized schema.
   In our messaging app’s normalized schema, there has to be a User type (a.k.a. User table, User collection) and a Room type. There also has to be a Message type, which looks like what you’d expect:
   And there has to be a RoomUser type, which stores facts about pairs, such as the last time user “ liron-shapira” (yours truly) saw the inside of room “r31” (conversation with Sasha Rosse):
   Notice that the aforementioned timestamp, 1310 (don’t try to make sense of these fake timestamp numbers), is before Sasha Rosse sent me a message containing the content “Perfect!” This is how the application knows that room r31 is an unread room, and how the UI decides to bold its fonts here:
更多图片 小图 大图
组图打开中,请稍候......
友荐云推荐




上一篇:Self-Study Plan for Becoming a Quantitative Trader
下一篇:Tools for writing the next best seller
酷辣虫提示酷辣虫禁止发表任何与中华人民共和国法律有抵触的内容!所有内容由用户发布,并不代表酷辣虫的观点,酷辣虫无法对用户发布内容真实性提供任何的保证,请自行验证并承担风险与后果。如您有版权、违规等问题,请通过"联系我们"或"违规举报"告知我们处理。

黄玲玲 发表于 2016-10-1 04:30:32
此贴必火,果断抱大腿。
回复 支持 反对

使用道具 举报

kxwh9bRy 发表于 2016-10-3 23:40:25
LZ是天才,坚定完毕
回复 支持 反对

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

我要投稿

推荐阅读

扫码访问 @iTTTTT瑞翔 的微博
回页顶回复上一篇下一篇回列表手机版
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 )|网站地图 酷辣虫

© 2001-2016 Comsenz Inc. Design: Dean. DiscuzFans.

返回顶部 返回列表