开源中国

我们不支持 IE 10 及以下版本浏览器

It appears you’re using an unsupported browser

为了获得更好的浏览体验,我们强烈建议您使用较新版本的 Chrome、 Firefox、 Safari 等,或者升级到最新版本的IE浏览器。 如果您使用的是 IE 11 或以上版本,请关闭“兼容性视图”。
为什么你不应该使用 MongoDB - 开源中国社区
当前位置:技术翻译 »  DBA/数据库 »  中英文对照

为什么你不应该使用 MongoDB

英文原文:Why You Should Never Use MongoDB

Disclaimer: I do not build database engines. I build web applications. I run 4-6 different projects every year, so I build a lot of web applications. I see apps with different requirements and different data storage needs. I’ve deployed most of the data stores you’ve heard about, and a few that you probably haven’t.

I’ve picked the wrong one a few times. This is a story about one of those times — why we picked it originally, how we discovered it was wrong, and how we recovered. It all happened on an open source project called Diaspora.

译者信息

译者信息

Garfielt
Garfielt
翻译于 4年前

1 此译文

免责声明:我不构建数据库引擎,但搭建Web应用。每年我大约跑4-6个不同项目,所以我搭建了不少Web应用。我经历过有不同需求及不同的数据存储需求的应用。我部署过你听说过或没听说过的的大部分数据存储。

我也有几次做出了错误的选择。这是一个关于其中一次的故事——原本我们为什么选择它,我们是如何发现它不合适,以及我们如何修复的。这一切都发生在一个开放源码的名为Diaspora的项目中。

The project

Diaspora is a distributed social network with a long history. Waaaaay back in early 2010, four undergraduates from New York University made a Kickstarter video asking for $10,000 to spend the summer building a distributed alternative to Facebook. They sent it out to friends and family, and hoped for the best.

But they hit a nerve. There had just been another Facebook privacy scandal, and when the dust settled on their Kickstarter, they had raised over $200,000 from 6400 different people for a software project that didn’t yet have a single line of code written.

Diaspora was the first Kickstarter project to vastly overrun its goal. As a result, they got written up in the New York Times – which turned into a bit of a scandal, because the chalkboard in the backdrop of the team photo had a dirty joke written on it, and no one noticed until it was actually printed. In the NEW YORK TIMES. The fallout from that was actually how I first heard about the project.

译者信息

译者信息

super0555
super0555
翻译于 4年前

1 此译文

Diaspora项目

Diaspora 是一个有着悠久历史的分布式社交网络。早在2010年初,纽约大学四名大学生创建了一个Kickstarter视频,目的是募集10000美元,耗费一个夏天来构建一个替代Facebook的分布式项目。他们将它发送给朋友和家人,并希望有最好的结果。

但他们触到了痛处。当时正好有另一起关于Facebook的隐私丑闻,当尘埃落定,回到他们的Kickstarter项目时,他们已经从6400个不同的人那里筹集了超过200000美元,而同时这个软件项目,却连一行代码都还没有写出来。

Diaspora是第一个大大超越其目标的Kickstarter项目。其结局是,他们的项目新闻被刊登于纽约时报——但它变成了一个丑闻,因为团队照片的背景黑板上面有一个肮脏的笑话,直到最终印刷都没有人注意到这一点。这可是刊登在纽约时报!这个事件的余波实际上是我第一次听说到这个项目。

As a result of their Kickstarter success, the guys left school and came out to San Francisco to start writing code. They ended up in my office. I was working at Pivotal Labs at the time, and one of the guys’ older brothers also worked there, so Pivotal offered them free desk space, internet, and, of course, access to the beer fridge. I worked with official clients during the day, then hung out with them after work and contributed code on weekends.

They ended up staying at Pivotal for more than two years. By the end of that first summer, though, they already had a minimal but working (for some definition) implementation of a distributed social network built in Ruby on Rails and backed by MongoDB.

That’s a lot of buzzwords. Let’s break it down.

译者信息

译者信息

Ley
Ley
翻译于 4年前

1 此译文

他们在Kickstarter上成功的结果,是离开学校,来到San Francisco开始写代码。他们最后在我的办公室工作。那时我在Pivotal实验室工作,他们的一个哥哥也在那工作,所以Pivotal给他们提供了免费的办公空间、网络,当然,装有啤酒的冰箱。我白天和官方客户工作,下班后和他们一起玩,周末贡献代码。

他们最后在Pivotal待了两年多的时间。虽然只是在第一个暑假的结尾,他们已经有了一个最小化的,但已经可以使用(在某种意义上说)的一个分布式社交网络,以Ruby on Rails实现,后端用MongoDB。

这里有很多流行词汇,让我们把它分解来看。

“Distributed social network”

If you’ve seen the Social Network, you know everything you need to know about Facebook. It’s a web app, it runs on a single logical server, and it lets you stay in touch with people. Once you log in, Diaspora’s interface looks structurally similar to Facebook’s:

A screenshot of the Diaspora interface

A screenshot of the Diaspora user interface

There’s a feed in the middle showing all your friends’ posts, and some other random stuff along the sides that no one has ever looked at. The main technical difference between Diaspora and Facebook is invisible to end users: it’s the “distributed” part.

译者信息

译者信息

Ley
Ley
翻译于 4年前

1 此译文

“分布式社交网络”

如果你看过《社交网络》,你就知道了所有你需要知道的关于Facebook的事。它是个web应用,它在一个单逻辑服务器上运行,它可以让你与朋友保持联系。一旦你登录,Diaspora的界面在结构上与Facebook很相似:

Diaspora用户界面的截图

在中间有个信息流,显示你所有朋友发布的信息,在边上有一些其他随机的基本没人关注过的东西。Diaspora和Facebook主要的技术差异在于对终端用户的不可见性:它是“分布的”部分。

The Diaspora infrastructure is not located behind a single web address. There are hundreds of independent Diaspora servers. The code is open source, so if you want to, you can stand up your own server. Each server, called a pod, has its own database and its own set of users, and will interoperate with all the other Diaspora pods that each have their own database and set of users.

The Diaspora Ecosystem

Pods of different sizes communicate with each other, without a central hub.

译者信息

译者信息

Ley
Ley
翻译于 4年前

1 此译文

Diaspora的基础设施并不在一个单独的网络地址上。有几百个独立的Diaspora服务器。代码是开源的,所以如果你愿意,你可以建立自己的服务器。各个服务器,被称作一个pod,有它自己的数据库和自己的用户集合,并可以与其他拥有各自数据库和用户集的Diaspora pod进行交互操作。

不同规模的Pod互相交流,而没有一个中央枢纽。

Each pod communicates with the others through an HTTP-based API. Once you set up an account on a pod, it’ll be pretty boring until you follow some other people. You can follow other users on your pod, and you can also follow people who are users on other pods. When someone you follow on another pod posts an update, here’s what happens:

1. The update goes into the author’s pod’s database.
2. Your pod is notified over the API.
3. The update is saved in your pod’s database.
4. You look at your activity feed and see that post mixed in with posts from the other people you follow.

Comments work the same way. On any single post, some comments might be from people on the same pod as the post’s author, and some might be from people on other pods. Everyone who has permission to see the post sees all the comments, just as you would expect if everyone were on a single logical server.

译者信息

译者信息

super0555
super0555
翻译于 4年前

1 此译文

每个pod通过基于HTTP的API与其它pod通信。一旦你在一个pod上创建了一个帐号,它其实相当无聊,除非你关注一些其他人。你可以在你的pod上关注其他用户,而且你也可以关注其它pod上的用户。当你关注的人在另一个pod上发布一个更新时,将会发生这些事情:


  1. 该更新会进入作者的pod的数据库。
  2. 你的pod会通过API收到通知。
  3. 该更新被存入你的pod的数据库。
  4. 你可以看看近期活动,将会发现这个发布与你关注的其他人的发布混在一起。

评论按同样的方式运作。在任何单一的发布中,一些评论的评论人可能来自与发布作者相同的pod,而还有一些可能来自其他的pod。任何有权查看这个发布的人将会看到所有的评论,就像你期待的,好像每个人都在一个单一的逻辑服务器上一样。

Who cares?

There are technical and legal advantages to this architecture. The main technical advantage is fault tolerance.

Here is a very important fault tolerant system that every office should have.

If any one of the pods goes down, it doesn’t bring the others down. The system survives, and even expects, network partitioning. There are some interesting political implications to that — for example, if you’re in a country that shuts down outgoing internet to prevent access to Facebook and Twitter, your pod running locally still connects you to other people within your country, even though nothing outside is accessible.

译者信息

译者信息

Ley
Ley
翻译于 4年前

2 此译文

谁关心?

这个架构有技术上和法律上的优势。技术上的主要优势在于容错机制

这是每个办公室都应该有的一个重要的容错系统。

如果pod中的任意一个宕机,这不会引起其他的也宕机。系统的生存,甚至期望,网络的分割。对于这,有一些有趣的政治上的暗示——例如,如果你在一个关闭了外接网络而无法访问Facebook和Twitter的国家,你的pod依旧会在本地运行,并和你所在国家内的其他人相连接,即使无法访问外部。

The main legal advantage is server independence. Each pod is a legally separate entity, governed by the laws of wherever it’s set up. Each pod also sets their own terms of service. On most of them, you can post content without giving up your rights to it, unlike on Facebook. Diaspora is free software both in the “gratis” and the “libre” sense of the term, and most of the people who run pods care deeply about that sort of thing.

So that’s the architecture of the system. Let’s look at the architecture within a single pod.

译者信息

译者信息

super0555
super0555
翻译于 4年前

1 此译文

主要的法律优势是服务器的独立性。每个pod都是一个法律独立的实体,由其创建所在地的法律所掌管。每个pod也设置自己的服务条款。对于其中的大多数,你可以在不放弃对内容权限的条件下发布内容,这与Facebook不同。Diaspora是一个免费的软件,其意义在于“免费”和“自由”,而且大多数运行pod的人非常在意这种事情。

所以这就是这个系统的架构。我们再来从一个单一的pod看看这个架构。

It’s a Rails app.

Each pod is a Ruby on Rails web application backed by a database, originally MongoDB. In some ways the codebase is a ‘typical’ Rails app — it has both a visual and programmatic UI, some Ruby code, and a database. But in other ways it is anything but typical.

The internal structure of one Diaspora pod

The visual UI is of course how website users interact with Diaspora. The API is used by various Diaspora mobile clients — that part’s pretty typical — but it’s also used for “federation,” which is the technical name for inter-pod communication. (I asked where the Romulans’ access point was once, and got a bunch of blank looks. Sigh.) So the distributed nature of the system adds layers to the codebase that aren’t present in a typical app.

And of course, MongoDB is an atypical choice for data storage. The vast majority of Rails applications are backed by PostgreSQL or (less often these days) MySQL.

So that’s the code. Let’s consider what kind of data we’re storing.

译者信息

译者信息

super0555
super0555
翻译于 4年前

1 此译文

这是一个 Rails 应用

每个pod都是一个Ruby on Rails应用,后端有一个数据库,最初是MongoDB。从某种程度来说,这个代码库是一个‘典型’的Rails应用——它同时具有一个可视化与可编程的UI,一些Ruby代码,以及一个数据库。但在其他方面,它决不是典型的。

一个 Diaspora pod的内部结构

视觉UI显然就是网站用户与Diaspora交互的方式。这个API被各种Diaspora移动客户端使用——这一部分相当典型——但同时它也被用于"federation"(联邦),这也是描述pod之间通讯的技术名词。(我有一次问过这与罗慕伦人的相似点在哪里,结果得到一堆白眼,擦。)所以说这个系统的分布式特性,给代码库增加了典型应用中所不存在的中间层。

当然,MongoDB是一种数据存储的典型选择。而绝大多数的Rails应用程序是由PostgreSQL(近来不常见)或MySQL所支持。

所以代码部分就是这样。我们再来考虑一下我们存储的是什么样的数据。

(译注:罗慕伦帝国是科幻系列《星际旅行》中虚构的外星帝国,2158年,罗慕伦帝国与当时的地球联邦发生了一场核战争。这场战争同时威胁到了其他的一些种族,并最终促使了星际联邦的建立。2160年罗慕伦人被打败,后与星际联邦签订合约并划定中立区。)

I Do Not Think That Word Means What You Think That Means

“Social data” is information about our network of friends, their friends, and their activity. Conceptually, we do think about it as a network — an undirected graph in which we are in the center, and our friends radiate out around us.

Photos all from rubyfriends.com. Thanks Matt Rogers, Steve Klabnik, Nell Shamrell, Katrina Owen, Sam Livingston-Grey, Josh Susser, Akshay Khole, Pradyumna Dandwate, and Hephzibah Watharkar for contributing to #rubyfriends!

When we store social data, we’re storing that graph topology, as well as the activity that moves along those edges.

译者信息

译者信息

Ley
Ley
翻译于 4年前

2 此译文

我不认为单词的意思是你认为的意思

“社交数据”是关于我们朋友、他们朋友和他们活动的网络信息。从概念上来看,我们确实认为它是一个网络——一个以我们为中心,朋友围绕在我们身边的无向网络。

所有照片来自rubyfriends.com。感谢Matt Rogers、Steve Klabnik、Nell Shamrell、Katrina Owen、Sam Livingston-Grey、Josh Susser、Akshay Khole、Pradyumna Dandwate和Hephzibah Watharkar对#rubyfriends的贡献!

当我们存储社交数据时,我们存储的是那个图的拓扑结构,和那些随着边移动的活动信息。

顶部