简体   繁体   English

GraphQL数据库设计模式

[英]GraphQL Database design patterns

I am researching on the technologies available to build a social network website. 我正在研究可用于建立社交网络网站的技术。 The front-end portion has been decided, but I am still unsure about the back-end. 前端部分已经确定,但我仍然不确定后端。 The back-end will also be handled by an server running NodeJS. 后端也将由运行NodeJS的服务器处理。 I was planning on using something like MongoDB, or even a combination of MongoDB and a relational database, but I do not know what the best practices are. 我计划使用像MongoDB这样的东西,甚至是MongoDB和关系数据库的组合,但我不知道最佳实践是什么。

I stumbled upon an article that talked about using GraphQL with different types of database structures. 我偶然发现了一篇文章 ,谈到了使用GraphQL和不同类型的数据库结构。 The writer mentioned SQL, Redis and MongoDB for their user data, but I did not quite understand their sturcture, or if it would work for mine. 作者提到SQL,Redis和MongoDB的用户数据,但我不太了解他们的结构,或者它是否适用于我的。

Basically I would like to have users to sign up to my page and add descriptions about themselves, have friends, join groups, upload media (pictures and videos), etc. A pretty basic social network setup, but ultimately the question narrows down to: 基本上我想让用户注册我的页面并添加关于他们的描述,有朋友,加入群组,上传媒体(图片和视频)等。这是一个非常基本的社交网络设置,但最终问题缩小为:

"What database structures are best for what?" “什么数据库结构最适合什么?”

Should the SQL handle: userID, email, password 应该处理SQL:userID,email,password
MongoDB: about, description, posts MongoDB:关于,描述,帖子
Redis: cache for something like posts feed Redis:缓存邮件提要等内容

And how would you handle media uploads? 你将如何处理媒体上传? SQL, MongoDB? SQL,MongoDB? I have not found any useful articles that talk about using different database structures and most of the other StackOverflow questions feel outdated. 我没有找到任何有用的文章谈论使用不同的数据库结构,大多数其他StackOverflow问题感觉已经过时。 They either favor one or another, but not a combination. 他们要么倾向于另一个,要么不是一个组合。

TL;DR : There aren't really any particular databases you "should use for GraphQL." TL; DR :实际上没有任何特定的数据库可以“用于GraphQL”。 Just use whatever is best suited for your data and requirements. 只需使用最适合您的数据和要求的任何内容。

I'll give you a rough idea how we use it at work. 我会粗略地告诉你我们在工作中如何使用它。 We have an app that lets users upload songs and videos for us to distribute to digital streaming platforms, eg Spotify and such. 我们有一个应用程序,允许用户上传歌曲和视频,以便我们分发到数字流媒体平台,例如Spotify等。

We use Postgres to handle all of the app's "transactional data." 我们使用Postgres来处理所有应用程序的“交易数据”。 This is user account info, their song/video metadata, where to send the money, other stuff for the app, etc. All these data are a mere few-hundred MB. 这是用户帐户信息,他们的歌曲/视频元数据,发送钱的地方,应用程序的其他内容等。所有这些数据只有几百MB。

Multimedia uploads go to AWS S3, and the location of each file is stored in Postgres. 多媒体上传到AWS S3,每个文件的位置都存储在Postgres中。

The "analytical data," regarding how well each song did on each platform, eg number of streams and money made in each region, is stored in Google BigQuery. 关于每首歌曲在每个平台上的表现如何,例如每个地区的流量和金钱数量的“分析数据”存储在Google BigQuery中。 There is much, much more of these data and Google BigQuery is more equipped for this size. 这些数据中有更多,更多,而Google BigQuery更适合这种规模。

Of course, the question of which data store one should use is highly case-dependent. 当然,应该使用哪个数据存储的问题高度依赖于案例。 GraphQL didn't really influence any of these decisions. GraphQL并没有真正影响这些决策。 The nice thing about GraphQL is that the resolvers let you pull data from anywhere and conglomerate it all into a single API response. 关于GraphQL的好处是,解析器允许您从任何地方提取数据并将其全部集成到单个API响应中。 By using GraphQL you should feel liberated to use a variety of databases, each well tailored to the type of data it handles. 通过使用GraphQL,您应该感到自由,使用各种数据库,每个数据库都根据其处理的数据类型进行定制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM