电子商务第三方API数据最佳实践

发布于 2024-08-05 07:42:29 字数 208 浏览 8 评论 0原文

对于以下情况,最佳做法是什么。我有一家电子商务商店,可以降低分销商的库存水平。每次用户加载产品详细信息页面时,网站是否应该使用第三方 API 来获取最新数据?或者,网站是否应该使用第三方 API,然后将该数据存储在自己的系统中一段时间​​并定期更新?

对我来说,很明显,每次加载产品详细信息页面时都应该更新它,但是高流量的电子商务商店又如何呢?对于这种情况是否使用了完全不同的解决方案?

What would be best practice for the following situation. I have an ecommerce store that pulls down inventory levels from a distributor. Should the site, for everytime a user loads a product detail page use the third party API for the most up to date data? Or, should the site using third party APIs and then store that data for a certain amount of time in it's own system and update it periodically?

To me it seems obvious that it should be updated everytime the product detail page is loaded but what about high traffic ecommerce stores? Are completely different solutions used for that case?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月亮邮递员 2024-08-12 07:42:29

在这种情况下,我肯定会将来自分销商站点的结果缓存一段时间,而不是每次收到请求时都点击它们。但是,我不会简单地对所有缓存条目使用 5 分钟或 30 分钟的超时。相反,我会使用一些启发法。如果可能的话,例如,如果您的应用程序是用 Python 等语言编写的,您可以将一个简单的脚本附加到每个实现超时的产品。

这样,如果是不经常请求的商品,或者库存量很大的商品,您可以缓存更长时间。

if product.popularityrating > 8 or product.lastqtyinstock < 20:
   cache.expire(productnum)
distributor.checkstock(productnum)

这为您提供了灵活性,您可以在需要时调用。最初,您可以将所有规则设置为以下内容:

 cache.expireover("3m",productnum)
 distributor.checkstock(productnum)

事实上,脚本可能不会包含 checkstock 函数调用,因为它位于主应用程序中,但它包含在此处是为了提供上下文。如果 python 看起来太重而无法仅包含这种少量的灵活性,那么看看 TCL,它是专门为此类工作而设计的。两者都可以轻松嵌入到 C、C++、C# 和 Java 应用程序中。

In this case I would definitely cache the results from the distributor's site for some period of time, rather than hitting them every time you get a request. However, I would not simply use a blanket 5 minute or 30 minute timeout for all cache entries. Instead, I would use some heuristics. If possible, for instance if your application is written in a language like Python, you could attach a simple script to every product which implements the timeout.

This way, if it is an item that is requested infrequently, or one that has a large amount in stock, you could cache for a longer time.

if product.popularityrating > 8 or product.lastqtyinstock < 20:
   cache.expire(productnum)
distributor.checkstock(productnum)

This gives you flexibility that you can call on if you need it. Initially, you can set all the rules to something like:

 cache.expireover("3m",productnum)
 distributor.checkstock(productnum)

In actual fact, the script would probably not include the checkstock function call because that would be in the main app, but it is included here for context. If python seems too heavyweiaght to include just for this small amount of flexibilty, then have a look at TCL which was specifically designed for this type of job. Both can be embedded easily in C, C++, C# and Java applications.

时间海 2024-08-12 07:42:29

事实上,还有另一种解决方案。您的经销商将产品目录保存在他们的服务器上,并允许您通过开放目录界面访问它。当用户想要下订单时,他会被重定向到经销商的目录,选择商品,然后将选择传输回您的商店。

它广泛应用于SRM(供应商关系管理)分支。

Actually, there is another solution. Your distributor keeps the product catalog on their servers and gives you access to it via Open Catalog Interface. When a user wants to make an order he gets redirected in-place to the distributor's catalog, chooses items then transfers selection back to your shop.

It is widely used in SRM (Supplier Relationship Management) branch.

叶落知秋 2024-08-12 07:42:29

这取决于许多因素:您网站的流量、库存水平变化的频率、显示过时数据对业务的影响、供应商允许您调用他们的 API 的频率、他们的 API 在可用性和性能方面的 SLA 等等在。

一旦你有了这些答案,这里当然有很多可能性。例如,对于低流量站点,正确获取库存非常重要,您可能希望在每次调用时都调用第 3 方 API,但如果 API 没有响应,则恢复到某些替代行为(例如使用缓存数据)在一定的超时时间内。

有时,设计良好的 API 会包含有关数据有效期的提示。例如,某些 REST-over-HTTP API 支持各种 HTTP 缓存控制标头,这些标头可用于指定有效期,或者仅检索自上次请求以来发生更改的数据。

It depends on many factors: the traffic to your site, how often the inventory levels change, the business impact of displaing outdated data, how often the supplers allow you to call their API, their API's SLA in terms of availability and performance, and so on.

Once you have these answers, there are of course many possibilities here. For example, for a low-traffic site where getting the inventory right is important, you may want to call the 3rd-party API on every call, but revert to some alternative behavior (such as using cached data) if the API does not respond within a certain timeout.

Sometimes, well-designed APIs will include hints as to the validity period of the data. For example, some REST-over-HTTP APIs support various HTTP Cache control headers that can be used to specify a validity period, or to only retrieve data if it has changed since last request.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文