如何设计HTTP API推送海量数据? [英] How to design HTTP API to push massive data?

查看:493
本文介绍了如何设计HTTP API推送海量数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为客户端提供HTTP API,以一组记录的形式推送大量数据. 我的第一个想法是提供一组三个呼叫,例如:

I need to provide an HTTP API for clients to push massive data, in the shape of a set of records. My first idea was to provide a set of three calls, like:

  • "BeginPushData"(无参数,返回ID)
  • "PushSomeData"(参数:ID,数据子集,无返回值)
  • "EndPushData"(参数:id)

第一个调用应用于初始化一些临时数据结构并为用户提供标识符,以便后续调用可以引用它,并且多个用户的数据也不会混乱.在所有数据都发送到服务器之前,应根据需要多次调用第二个调用.最后,调用最后一个调用,客户端确认所有数据都已推送,因此服务器可以处理刚刚存储的所有临时数据.

The first call should be used to initialize some temporary data structure and give the user an identifier, so that subsequent calls can refer to it and data from multiple users don't mess up. The second call should be invoked as many times as needed, until all data is sent to the server. Finally, invoking the last call, the client confirms that all data has been pushed, so the server can process all the temporary data just stored.

通常,遵循REST原则被认为是一种好习惯,但是这种上传大数据的策略显然违反了无状态的REST原则.因此,我正在寻找一种更好的替代方法来完成这项工作.对知名模式的引用将不胜感激!

In general, it's considered a good practice to conform to REST principles, but this strategy of uploading large data clearly violates the REST principle of being stateless. For this reason, I'm looking for some better alternative way of doing the job. References to well-known patterns would be appreciated!

推荐答案

该设计对我来说听起来很合理,我认为它符合

The design sounds perfectly reasonable to me, and I think it conforms to the ReSTful principle of Statelessness as well.

从客户端到服务器的每个请求必须包含理解该请求所需的所有信息,并且不能利用服务器上存储的任何上下文.

Each request from the client to server must contain all of the information necessary to understand the request, and cannot take advantage of any stored context on the server.

从初始推送返回的id满足了该要求. id由应用程序维护和重用;因此服务器上没有存储会话状态,只有资源状态.

That requirement is satisfied by the id returned from the initial push. The id is maintained and reused by the application; so there is no session state stored on the server, only resource state.

这篇关于如何设计HTTP API推送海量数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆