Netflix的实用API设计,第二部分:突变操作的Protobuf FieldMask

By Ricky Gardiner, Alex Borysov

通过 里奇-加德纳, 亚历克斯-鲍里索夫

Background

背景介绍

In our previous post, we discussed how we utilize FieldMask as a solution when designing our APIs so that consumers can request the data they need when fetched via gRPC. In this blog post we will continue to cover how Netflix Studio Engineering uses FieldMask for mutation operations such as update and remove.

上一篇文章中,我们讨论了在设计我们的API时如何利用FieldMask作为解决方案,以便消费者在通过gRPC获取数据时可以请求他们需要的数据。在这篇博文中,我们将继续介绍Netflix Studio Engineering如何利用FieldMask进行更新和删除等突变操作。

Example: Netflix Studio Production

例子。网飞工作室制作

Money Heist (La casa de papel) / Netflix

抢钱》(La casa de papel)/ Netflix

Previously we outlined what a Production is and how the Production Service makes gRPC calls to other microservices such as the Schedule Service and Script Service to retrieve schedules and scripts (aka screenplay) for a particular production such as La Casa De Papel. We can take that model and showcase how we can mutate particular fields on a production.

之前我们概述了什么是生产,以及生产服务如何以gRPC方式调用其他微服务,如日程表服务和脚本服务,以检索特定生产的日程表和脚本(又称剧本),如La Casa De Papel。我们可以采用这个模型,并展示我们如何在一个产品上突变特定的字段。

Mutating Production Details

突变的生产细节

Let’s say we want to update the format field from LIVE_ACTION to HYBRID as our production has added some animated elements. A naive way for us to solve this is to add an updateProductionFormatRequest method and gRPC endpoint just to update the productionFormat:

比方说,我们想把format 字段从LIVE_ACTION 更新到HYBRID ,因为我们的生产增加了一些动画元素。我们解决这个问题的一个天真的方法是添加一个updateProductionFormatRequest方法和gRPC端点来更新productionFormat。

This allows us to update the production format for a particular production but what if we then want to update other fields such as titleor even multiple fields such as productionFormat, schedule, etc? Building on top of this we could just implement an update method for every field: one for Production format, another for title and so on:

这允许我们更新某个特定作品的生产格式,但如果我们想更新其他字段,如title,甚至多个字段,如productionFormat,schedule ,等等,怎么办?在此基础上,我们可以为每个字段实现一个更新方法:一个用于生产格式,另一个用于标题,等等。

This can become unmanageable when main...

开通本站会员,查看完整译文。

首页 - Wiki
Copyright © 2011-2024 iteam. Current version is 2.125.0. UTC+08:00, 2024-05-08 02:08
浙ICP备14020137号-1 $访客地图$