SlideShare a Scribd company logo
1 of 47
Download to read offline
Part 3 Fundamentals
8. Partial Updates and Retrievals
Rick Hwang
2022/04/20
1
● Why we might want to update or retrieve only
specific pieces of a resource
○ 鄉民都只對特殊資訊感興趣
● How best to communicate the fields of interest
to the API service
○ 鄉民都只對自己有利的感興趣
● How to handle individual items in complex
fields, such as maps and interfaces
● Whether to support addressing individual items
in a repeated field (e.g., arrays)
● Defining default values and handling implicit
field masks
● How to deal with invalid field specifications
2
● Why we might want to update or retrieve only
specific pieces of a resource
○ 鄉民都只對特殊資訊感興趣
● How best to communicate the fields of interest
to the API service
○ 鄉民都只對自己有利的感興趣
● How to handle individual items in complex
fields, such as maps and interfaces
● Whether to support addressing individual items
in a repeated field (e.g., arrays)
● Defining default values and handling implicit
field masks
● How to deal with invalid field specifications
8.1.1 Partial retrieval
○ 取的整個 Resource 是必要的?
○ 如果 Resource 的資料結構有數百的 fields or
subfields?
○ 需要針對特殊的情境,限制取得的 fields,例如:
○ 很小的 IoT 設備 - 硬體資源限制
○ PII - 資安政策 (Member Service)
○ 不是所有 Client 都需要取得全部內容
8.1 Motivation
8.1.2 Partial update
● 能否針對個別的 fields 修改?
● 確保資料更新後的一致性
● 標準方法不夠用的時候怎麼辦?
3
4
aws ec2 describe-instances
5
Protocol Data Structure
Web Services HTTP/1.1 SOAP / XML
REST HTTP/1.1 JSON
gRPC HTTP/2 Protobuf
補
充
Note: User1 與 User2 針對同一個 Object,循序的改動不一樣的屬性。
6
7
1. Resource 新增
description field,也提供
新的 client
2. 舊的 client 持續在使用
=> 想像是 HTTP Client
or SDK 那種
3. 沒有考慮 back
compatible 就會出現
data loss
1
2
3
1. 循序性的寫入,需要一致性檢查 (consistency checks)、或者 locking
2. versioning and compatiablity, see chatper 24
a. support new features
b. fix bugs
c. to add new fields to resources while still considering the new version backward compatible
核心問題
8
1. Enabling partial retrievals => GET
2. Enabling partial updates => PATCH
8.2 Overview - Goals
9
a field mask is just a collection of strings, but these
strings represent a list of fields that we’re interested in
on a given resource.
The Field Mask
● Enabling partial retrievals and
pr
10
11
12
8.3 Implementation
How we transport the field mask without causing any significant
disruption to the standard requests that defined in chapter 7.
13
8.2.1 Transport
two constraints:
1. GET: no body to the request permitted
(and many HTTP servers will strip it out if
one is provided)
2. PATCH: resource-oriented design
dictates that the body of a PATCH
request must be the resource
representation being updated
two potential places:
1. headers
2. query strings: how the repeated query
string parameters are interpreted will
depend on the HTTP server in use
14
15
GET with query string, body, header PATCH with query string, body, header
16
HTTP Methods Query String Body HTTP Header
GET v v (?) v
PATCH v v v
Node.JS (express)
HTTP Methods Query String Body HTTP Header
GET v ?? v
PATCH v
ASP.NET (Kestrel)
17
ASP.NET (C#) ?fieldMask=a&fieldMask=b string
have to augment the request
messages for both the standard
update method and standard get
method.
18
Does this idea of partial updates
and retrievals extend inside nested
structures?
Or does it only apply at the very
top level, effectively treating
resources as completely flat
structures?
8.3.2 Maps and nested interface
19
How to represent field:
maxMessageCount
● JSON Path: $.loggingConfig.maxMEssageCount
20
1. Separate parts of a field specification
must use a dot character (.) as a
separator.
2. All fields of a nested message may be
referred to using an asterisk character
(*).
3. Map keys should always be strings.
4. All parts of a field specification that
can’t be represented as an unquoted
string literal must be quoted using
backtick characters (`).
5. A literal backtick character may be
escaped by using two backtick
characters (``)
Rules for field mask to specify nested fields.
21
JSON Path
XPath (for XML)
https://github.com/json-path/JsonPath
https://zh.wikipedia.org/zh-tw/XPath
→ XSTL (時代的眼淚)
22
補
充
23
8.3.3 Repeated fields
● prefix of "administrators.*." as a way of
saying “For each administrator
● retrieve only the name of an administrator,
use a field mask value of
"administrators.*.name"
24
8.3.4 Default values
the goal of a default value is to do “the right thing” for the user.
GET: standard get method, the default is almost always the complete list of fields
available on a resource.
標準 GET 會取得所有的 Fields
There is an exception to this guideline. In cases where a resource has fields
which, for whatever reason, would cause a fundamentally worse user experience
for API consumers, these fields should be removed from the default of the field
mask being left unset.
如果有一些 Fields 會導致 API 使用者的使用體驗不好,這些 fields 應該從 field mask 的預設中 被移除
使用者有興趣的時候,自行透過 fieldMask 指定 Fields 取得。
25
GET /api/chatrooms?fieldMask=participants
{
"1": {
"id": 1,
"title": "My Chat!",
"description": "喇低賽",
"participants": [] ⇐ 裡面有 10k 個鄉民,要處理很久
},
"2": {
"id": 2,
"title": "Your Chat!",
"description": "低賽喇",
"participants": [] ⇐ 裡面有 100k 個鄉民,要處理很久
}
}
Design: w/o participants in default
GET /api/chatrooms <Default>
{
"1": {
"id": 1,
"title": "My Chat!",
"description": "喇低賽",
},
"2": {
"id": 2,
"title": "Your Chat!",
"description": "低賽喇",
}
}
26
w/o participants
預設 = 製造了淺規則?
● 文件要明確說明,預設 fieldMask 的行為
● 即使有文件,還是很容易誤解。
● 不想讓使用者猜測哪些 fields 是預設的?
● 使用 asterick (“*”) 表示返回所有的 fields
● 取得資源使用預設 fieldMask 是用,但是更
新資源,Default FieldMask 就沒啥用
GET /api/chatrooms?fieldMask=*
{
"1": {
"id": 1,
"title": "My Chat!",
"description": "喇低賽",
"participants": [] ⇐ 裡面有 10k 個鄉民,要處理很久
}
}
GET /api/chatrooms?fieldMask=id,title
{
"1": {
"id": 1,
"title": "My Chat!",
}
}
27
個
人
觀
點
DesignA: 特定欄位的正向表列?
Design B: 全部欄位的正向表列?
預設 = Policy (政策 / 慣例 / 文化 / 潛規則)
● 衝突來源
● 怪異
● 高雄式左轉
● 習慣遲到
● 公司的淺規則
● 默契
● 共識
● 守法
● 提前到、準時
● 91APP 的政策
28
個
人
觀
點
預設
● 專業領域 (Domain Know How)
● 企業文化
● 鄉民文化
● 潛在共識
● 生態系
○ .NET method name starts with uppercase
○ Java method name starts with lowercase
29
個
人
觀
點
The goal of a default value is to do “the right thing” for the user.
啥叫做正確的事情? ← 這句話不夠具體
● 給不同使用者,最必要的資訊。
○ Chatroom 的參與者,需要怎樣的聊天室資訊?
○ Chatroom 的管理者,需要怎樣的聊天室資訊?
● 91APP 的專業判斷 => Domain Expert 必須思考的 => PO + Team
○ 對於 會員 (消費者) 而言,訂單 (Order) 要呈現什麼資訊?
○ 對於 91APP 的客戶 而言,訂單 (Order) 要呈現什麼資訊?
○ 對於 91APP 營管 而言,訂單 (Order) 要呈現什麼資訊?
○ 對於 91APP 合作夥伴 而言,訂單 (Order) 要呈現什麼資訊?
30
個
人
觀
點
What does an unset field mask mean on a standard update method (using an
HTTP PATCH method)?
8.3.5 Implicit field masks
31
32
What does an unset field mask mean on a standard update method (using an
HTTP PATCH method)?
Most commonly, HTTP PATCH indicates an intent to update the resource with only
the data provided in the body of the request.
8.3.5 Implicit field masks
33
8.3.5 Implicit field masks
34
PATCH/chatRooms/1
{"description":"Newdescription"}
// 只更新 id=1 的 description
● dynamic data structure => object 型別
○ ch5 提到的是 static data structure
● settings.test 有三種值:
○ “STRING_VALUE”
○ null
○ 不存在
● 如果要刪除 settings.test 要怎麼做?
○ 不是 null
○ “undefined” 不是 JSON 資料型別
註:“undefined” 是語言層級的型別。
8.3.6 Updating dynamic data structures
35
36
8.3.6 Updating dynamic data structures
● settings.test 有三種值:
○ “STRING_VALUE”
○ null
○ 不存在 => undefined 的意思
● 如果要刪除 settings.test 要怎麼做?
○ 不是 null
● “undefined” 不是 JSON 資料型別,是 JS
語言層級的型別。
○ python 可能是 None
37
透過 FieldMask
38
針對 “dynamic data structures” 的理解 Q_Q
39
個
人
觀
點
v1 v2
8.3.7 Invalid fields=> 參閱 CH24 Versioning and compatibility
40
個
人
觀
點
=>
ch24
v1 v2
● the goal is still quite limited:
a. to minimize unnecessary data transfer and
b. allow fine-grained modification of API resources.
● consider field masks and partial retrievals in particular as SQL-like querying tools to fetch specific
data
8.4 Trade-offs
41
這章講的概念,是不是很像某個東西的自幹版?
42
Bo 先生:啥時候才有 GraphQL 的 Design Guideline 啊?
43
8.4.1 Universal support
44
● NOT at all a requirement that every API must support partial retrieval.
● more an issue of concurrency than resource size and complexity
是否需要刻個 Libraries 實踐這些通用規則?
C# 開發者表示:這還要問?
Node.JS 開發者表示:我也要
Java 開發者表示:我也要
PHP 開發者表示:我。。。
45
個
人
觀
點
8.4.2 Alternative implementations
● JSON Patch (RFC6902), (npm)
● JSON Merge Patch (RFC7396), (npm)
● 哪裡有類似的概念:K8s 實作
○ kubectl apply -f xxx.yaml
46
1. Partial retrieval is particularly important in cases where resources are large or
clients consuming resource data have limited hardware. => POS
2. Partial updates are critical for fine-grained updates without worrying about conflicts.
3. Field masks, which support ways to address fields, nested fields in interfaces, and
map keys, should be used to indicate the fields that should be retrieved or updated.
4. Field masks should NOT provide a mechanism to address items in array fields by
their position or index in that field.
5. By default, field masks should assume a value of everything for partial retrievals and
an implicit field mask (8.3.5) for partial updates.
6. If fields are invalid, they should be treated as though they do exist but have a value
of undefined.
Summary
47

More Related Content

Similar to Chapter 8. Partial updates and retrievals.pdf

Everything I Ever Learned About JVM Performance Tuning @Twitter
Everything I Ever Learned About JVM Performance Tuning @TwitterEverything I Ever Learned About JVM Performance Tuning @Twitter
Everything I Ever Learned About JVM Performance Tuning @TwitterAttila Szegedi
 
Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?Felix Geisendörfer
 
Exploiting GPU's for Columnar DataFrrames by Kiran Lonikar
Exploiting GPU's for Columnar DataFrrames by Kiran LonikarExploiting GPU's for Columnar DataFrrames by Kiran Lonikar
Exploiting GPU's for Columnar DataFrrames by Kiran LonikarSpark Summit
 
Rook - cloud-native storage
Rook - cloud-native storageRook - cloud-native storage
Rook - cloud-native storageKarol Chrapek
 
SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...
SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...
SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...Chester Chen
 
Polyglot persistence @ netflix (CDE Meetup)
Polyglot persistence @ netflix (CDE Meetup) Polyglot persistence @ netflix (CDE Meetup)
Polyglot persistence @ netflix (CDE Meetup) Roopa Tangirala
 
20111018 boost and gtest
20111018 boost and gtest20111018 boost and gtest
20111018 boost and gtestWill Shen
 
New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2
New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2
New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2Antonios Giannopoulos
 
Apache Hadoop YARN 3.x in Alibaba
Apache Hadoop YARN 3.x in AlibabaApache Hadoop YARN 3.x in Alibaba
Apache Hadoop YARN 3.x in AlibabaDataWorks Summit
 
Hypertable - massively scalable nosql database
Hypertable - massively scalable nosql databaseHypertable - massively scalable nosql database
Hypertable - massively scalable nosql databasebigdatagurus_meetup
 
Grow and Shrink - Dynamically Extending the Ruby VM Stack
Grow and Shrink - Dynamically Extending the Ruby VM StackGrow and Shrink - Dynamically Extending the Ruby VM Stack
Grow and Shrink - Dynamically Extending the Ruby VM StackKeitaSugiyama1
 
DConf2015 - Using D for Development of Large Scale Primary Storage
DConf2015 - Using D for Development  of Large Scale Primary StorageDConf2015 - Using D for Development  of Large Scale Primary Storage
DConf2015 - Using D for Development of Large Scale Primary StorageLiran Zvibel
 
3 boyd direct3_d12 (1)
3 boyd direct3_d12 (1)3 boyd direct3_d12 (1)
3 boyd direct3_d12 (1)mistercteam
 
24-02-18 Rejender pratap.pdf
24-02-18 Rejender pratap.pdf24-02-18 Rejender pratap.pdf
24-02-18 Rejender pratap.pdfFrangoCamila
 
How YugaByte DB Implements Distributed PostgreSQL
How YugaByte DB Implements Distributed PostgreSQLHow YugaByte DB Implements Distributed PostgreSQL
How YugaByte DB Implements Distributed PostgreSQLYugabyte
 
Sorry - How Bieber broke Google Cloud at Spotify
Sorry - How Bieber broke Google Cloud at SpotifySorry - How Bieber broke Google Cloud at Spotify
Sorry - How Bieber broke Google Cloud at SpotifyNeville Li
 
In-memory No SQL- GIDS2014
In-memory No SQL- GIDS2014In-memory No SQL- GIDS2014
In-memory No SQL- GIDS2014Hazelcast
 
Scale Relational Database with NewSQL
Scale Relational Database with NewSQLScale Relational Database with NewSQL
Scale Relational Database with NewSQLPingCAP
 

Similar to Chapter 8. Partial updates and retrievals.pdf (20)

Everything I Ever Learned About JVM Performance Tuning @Twitter
Everything I Ever Learned About JVM Performance Tuning @TwitterEverything I Ever Learned About JVM Performance Tuning @Twitter
Everything I Ever Learned About JVM Performance Tuning @Twitter
 
Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?Nodejs - Should Ruby Developers Care?
Nodejs - Should Ruby Developers Care?
 
Exploiting GPU's for Columnar DataFrrames by Kiran Lonikar
Exploiting GPU's for Columnar DataFrrames by Kiran LonikarExploiting GPU's for Columnar DataFrrames by Kiran Lonikar
Exploiting GPU's for Columnar DataFrrames by Kiran Lonikar
 
Rook - cloud-native storage
Rook - cloud-native storageRook - cloud-native storage
Rook - cloud-native storage
 
SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...
SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...
SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...
 
Java Memory Model
Java Memory ModelJava Memory Model
Java Memory Model
 
Polyglot persistence @ netflix (CDE Meetup)
Polyglot persistence @ netflix (CDE Meetup) Polyglot persistence @ netflix (CDE Meetup)
Polyglot persistence @ netflix (CDE Meetup)
 
20111018 boost and gtest
20111018 boost and gtest20111018 boost and gtest
20111018 boost and gtest
 
New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2
New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2
New Indexing and Aggregation Pipeline Capabilities in MongoDB 4.2
 
dev_int_96
dev_int_96dev_int_96
dev_int_96
 
Apache Hadoop YARN 3.x in Alibaba
Apache Hadoop YARN 3.x in AlibabaApache Hadoop YARN 3.x in Alibaba
Apache Hadoop YARN 3.x in Alibaba
 
Hypertable - massively scalable nosql database
Hypertable - massively scalable nosql databaseHypertable - massively scalable nosql database
Hypertable - massively scalable nosql database
 
Grow and Shrink - Dynamically Extending the Ruby VM Stack
Grow and Shrink - Dynamically Extending the Ruby VM StackGrow and Shrink - Dynamically Extending the Ruby VM Stack
Grow and Shrink - Dynamically Extending the Ruby VM Stack
 
DConf2015 - Using D for Development of Large Scale Primary Storage
DConf2015 - Using D for Development  of Large Scale Primary StorageDConf2015 - Using D for Development  of Large Scale Primary Storage
DConf2015 - Using D for Development of Large Scale Primary Storage
 
3 boyd direct3_d12 (1)
3 boyd direct3_d12 (1)3 boyd direct3_d12 (1)
3 boyd direct3_d12 (1)
 
24-02-18 Rejender pratap.pdf
24-02-18 Rejender pratap.pdf24-02-18 Rejender pratap.pdf
24-02-18 Rejender pratap.pdf
 
How YugaByte DB Implements Distributed PostgreSQL
How YugaByte DB Implements Distributed PostgreSQLHow YugaByte DB Implements Distributed PostgreSQL
How YugaByte DB Implements Distributed PostgreSQL
 
Sorry - How Bieber broke Google Cloud at Spotify
Sorry - How Bieber broke Google Cloud at SpotifySorry - How Bieber broke Google Cloud at Spotify
Sorry - How Bieber broke Google Cloud at Spotify
 
In-memory No SQL- GIDS2014
In-memory No SQL- GIDS2014In-memory No SQL- GIDS2014
In-memory No SQL- GIDS2014
 
Scale Relational Database with NewSQL
Scale Relational Database with NewSQLScale Relational Database with NewSQL
Scale Relational Database with NewSQL
 

More from Rick Hwang

在生命轉彎的地方 - 從軟體開發職涯,探索人生
在生命轉彎的地方 - 從軟體開發職涯,探索人生在生命轉彎的地方 - 從軟體開發職涯,探索人生
在生命轉彎的地方 - 從軟體開發職涯,探索人生Rick Hwang
 
20230829 - 探索職涯,複利人生
20230829 - 探索職涯,複利人生20230829 - 探索職涯,複利人生
20230829 - 探索職涯,複利人生Rick Hwang
 
2023 08 - SRE 實踐與開發平台指南 - 書友見面會
2023 08 - SRE 實踐與開發平台指南 - 書友見面會2023 08 - SRE 實踐與開發平台指南 - 書友見面會
2023 08 - SRE 實踐與開發平台指南 - 書友見面會Rick Hwang
 
20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)
20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)
20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)Rick Hwang
 
軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大
軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大
軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大Rick Hwang
 
CH02 API Governance
CH02 API Governance CH02 API Governance
CH02 API Governance Rick Hwang
 
Ch09 Custom Methods
Ch09 Custom MethodsCh09 Custom Methods
Ch09 Custom MethodsRick Hwang
 
AWS Career Exploration Day
AWS Career Exploration DayAWS Career Exploration Day
AWS Career Exploration DayRick Hwang
 
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)Rick Hwang
 
SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路
SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路
SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路Rick Hwang
 
導讀持續交付 2.0 - CH02 價值探索環
導讀持續交付 2.0 - CH02 價值探索環 導讀持續交付 2.0 - CH02 價值探索環
導讀持續交付 2.0 - CH02 價值探索環 Rick Hwang
 
2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構
2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構
2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構Rick Hwang
 
災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)
災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)
災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)Rick Hwang
 
Software Development Process v1.5 - 20121214
Software Development Process v1.5 - 20121214Software Development Process v1.5 - 20121214
Software Development Process v1.5 - 20121214Rick Hwang
 
第三章 建立良好的人際關係網路
第三章 建立良好的人際關係網路第三章 建立良好的人際關係網路
第三章 建立良好的人際關係網路Rick Hwang
 
Wiki in Teamroom - Connected Mind
Wiki in Teamroom - Connected MindWiki in Teamroom - Connected Mind
Wiki in Teamroom - Connected MindRick Hwang
 
導讀持續交付 2.0 - 談當代軟體交付之虛實融合
導讀持續交付 2.0 - 談當代軟體交付之虛實融合導讀持續交付 2.0 - 談當代軟體交付之虛實融合
導讀持續交付 2.0 - 談當代軟體交付之虛實融合Rick Hwang
 
Study Notes - Event-Driven Data Management for Microservices
Study Notes - Event-Driven Data Management for MicroservicesStudy Notes - Event-Driven Data Management for Microservices
Study Notes - Event-Driven Data Management for MicroservicesRick Hwang
 
Study Notes - Using an API Gateway
Study Notes - Using an API GatewayStudy Notes - Using an API Gateway
Study Notes - Using an API GatewayRick Hwang
 
從緊急事件 談 SRE 應變能力的培養 - DevOpsDays Taipei 2018
從緊急事件  談 SRE 應變能力的培養 - DevOpsDays Taipei 2018從緊急事件  談 SRE 應變能力的培養 - DevOpsDays Taipei 2018
從緊急事件 談 SRE 應變能力的培養 - DevOpsDays Taipei 2018Rick Hwang
 

More from Rick Hwang (20)

在生命轉彎的地方 - 從軟體開發職涯,探索人生
在生命轉彎的地方 - 從軟體開發職涯,探索人生在生命轉彎的地方 - 從軟體開發職涯,探索人生
在生命轉彎的地方 - 從軟體開發職涯,探索人生
 
20230829 - 探索職涯,複利人生
20230829 - 探索職涯,複利人生20230829 - 探索職涯,複利人生
20230829 - 探索職涯,複利人生
 
2023 08 - SRE 實踐與開發平台指南 - 書友見面會
2023 08 - SRE 實踐與開發平台指南 - 書友見面會2023 08 - SRE 實踐與開發平台指南 - 書友見面會
2023 08 - SRE 實踐與開發平台指南 - 書友見面會
 
20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)
20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)
20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)
 
軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大
軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大
軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大
 
CH02 API Governance
CH02 API Governance CH02 API Governance
CH02 API Governance
 
Ch09 Custom Methods
Ch09 Custom MethodsCh09 Custom Methods
Ch09 Custom Methods
 
AWS Career Exploration Day
AWS Career Exploration DayAWS Career Exploration Day
AWS Career Exploration Day
 
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
 
SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路
SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路
SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路
 
導讀持續交付 2.0 - CH02 價值探索環
導讀持續交付 2.0 - CH02 價值探索環 導讀持續交付 2.0 - CH02 價值探索環
導讀持續交付 2.0 - CH02 價值探索環
 
2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構
2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構
2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構
 
災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)
災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)
災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)
 
Software Development Process v1.5 - 20121214
Software Development Process v1.5 - 20121214Software Development Process v1.5 - 20121214
Software Development Process v1.5 - 20121214
 
第三章 建立良好的人際關係網路
第三章 建立良好的人際關係網路第三章 建立良好的人際關係網路
第三章 建立良好的人際關係網路
 
Wiki in Teamroom - Connected Mind
Wiki in Teamroom - Connected MindWiki in Teamroom - Connected Mind
Wiki in Teamroom - Connected Mind
 
導讀持續交付 2.0 - 談當代軟體交付之虛實融合
導讀持續交付 2.0 - 談當代軟體交付之虛實融合導讀持續交付 2.0 - 談當代軟體交付之虛實融合
導讀持續交付 2.0 - 談當代軟體交付之虛實融合
 
Study Notes - Event-Driven Data Management for Microservices
Study Notes - Event-Driven Data Management for MicroservicesStudy Notes - Event-Driven Data Management for Microservices
Study Notes - Event-Driven Data Management for Microservices
 
Study Notes - Using an API Gateway
Study Notes - Using an API GatewayStudy Notes - Using an API Gateway
Study Notes - Using an API Gateway
 
從緊急事件 談 SRE 應變能力的培養 - DevOpsDays Taipei 2018
從緊急事件  談 SRE 應變能力的培養 - DevOpsDays Taipei 2018從緊急事件  談 SRE 應變能力的培養 - DevOpsDays Taipei 2018
從緊急事件 談 SRE 應變能力的培養 - DevOpsDays Taipei 2018
 

Recently uploaded

Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 

Recently uploaded (20)

Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 

Chapter 8. Partial updates and retrievals.pdf

  • 1. Part 3 Fundamentals 8. Partial Updates and Retrievals Rick Hwang 2022/04/20 1 ● Why we might want to update or retrieve only specific pieces of a resource ○ 鄉民都只對特殊資訊感興趣 ● How best to communicate the fields of interest to the API service ○ 鄉民都只對自己有利的感興趣 ● How to handle individual items in complex fields, such as maps and interfaces ● Whether to support addressing individual items in a repeated field (e.g., arrays) ● Defining default values and handling implicit field masks ● How to deal with invalid field specifications
  • 2. 2 ● Why we might want to update or retrieve only specific pieces of a resource ○ 鄉民都只對特殊資訊感興趣 ● How best to communicate the fields of interest to the API service ○ 鄉民都只對自己有利的感興趣 ● How to handle individual items in complex fields, such as maps and interfaces ● Whether to support addressing individual items in a repeated field (e.g., arrays) ● Defining default values and handling implicit field masks ● How to deal with invalid field specifications
  • 3. 8.1.1 Partial retrieval ○ 取的整個 Resource 是必要的? ○ 如果 Resource 的資料結構有數百的 fields or subfields? ○ 需要針對特殊的情境,限制取得的 fields,例如: ○ 很小的 IoT 設備 - 硬體資源限制 ○ PII - 資安政策 (Member Service) ○ 不是所有 Client 都需要取得全部內容 8.1 Motivation 8.1.2 Partial update ● 能否針對個別的 fields 修改? ● 確保資料更新後的一致性 ● 標準方法不夠用的時候怎麼辦? 3
  • 5. 5 Protocol Data Structure Web Services HTTP/1.1 SOAP / XML REST HTTP/1.1 JSON gRPC HTTP/2 Protobuf 補 充
  • 6. Note: User1 與 User2 針對同一個 Object,循序的改動不一樣的屬性。 6
  • 7. 7 1. Resource 新增 description field,也提供 新的 client 2. 舊的 client 持續在使用 => 想像是 HTTP Client or SDK 那種 3. 沒有考慮 back compatible 就會出現 data loss 1 2 3
  • 8. 1. 循序性的寫入,需要一致性檢查 (consistency checks)、或者 locking 2. versioning and compatiablity, see chatper 24 a. support new features b. fix bugs c. to add new fields to resources while still considering the new version backward compatible 核心問題 8
  • 9. 1. Enabling partial retrievals => GET 2. Enabling partial updates => PATCH 8.2 Overview - Goals 9 a field mask is just a collection of strings, but these strings represent a list of fields that we’re interested in on a given resource.
  • 10. The Field Mask ● Enabling partial retrievals and pr 10
  • 11. 11
  • 12. 12
  • 13. 8.3 Implementation How we transport the field mask without causing any significant disruption to the standard requests that defined in chapter 7. 13
  • 14. 8.2.1 Transport two constraints: 1. GET: no body to the request permitted (and many HTTP servers will strip it out if one is provided) 2. PATCH: resource-oriented design dictates that the body of a PATCH request must be the resource representation being updated two potential places: 1. headers 2. query strings: how the repeated query string parameters are interpreted will depend on the HTTP server in use 14
  • 15. 15 GET with query string, body, header PATCH with query string, body, header
  • 16. 16 HTTP Methods Query String Body HTTP Header GET v v (?) v PATCH v v v Node.JS (express) HTTP Methods Query String Body HTTP Header GET v ?? v PATCH v ASP.NET (Kestrel)
  • 18. have to augment the request messages for both the standard update method and standard get method. 18
  • 19. Does this idea of partial updates and retrievals extend inside nested structures? Or does it only apply at the very top level, effectively treating resources as completely flat structures? 8.3.2 Maps and nested interface 19
  • 20. How to represent field: maxMessageCount ● JSON Path: $.loggingConfig.maxMEssageCount 20
  • 21. 1. Separate parts of a field specification must use a dot character (.) as a separator. 2. All fields of a nested message may be referred to using an asterisk character (*). 3. Map keys should always be strings. 4. All parts of a field specification that can’t be represented as an unquoted string literal must be quoted using backtick characters (`). 5. A literal backtick character may be escaped by using two backtick characters (``) Rules for field mask to specify nested fields. 21
  • 22. JSON Path XPath (for XML) https://github.com/json-path/JsonPath https://zh.wikipedia.org/zh-tw/XPath → XSTL (時代的眼淚) 22 補 充
  • 23. 23
  • 24. 8.3.3 Repeated fields ● prefix of "administrators.*." as a way of saying “For each administrator ● retrieve only the name of an administrator, use a field mask value of "administrators.*.name" 24
  • 25. 8.3.4 Default values the goal of a default value is to do “the right thing” for the user. GET: standard get method, the default is almost always the complete list of fields available on a resource. 標準 GET 會取得所有的 Fields There is an exception to this guideline. In cases where a resource has fields which, for whatever reason, would cause a fundamentally worse user experience for API consumers, these fields should be removed from the default of the field mask being left unset. 如果有一些 Fields 會導致 API 使用者的使用體驗不好,這些 fields 應該從 field mask 的預設中 被移除 使用者有興趣的時候,自行透過 fieldMask 指定 Fields 取得。 25
  • 26. GET /api/chatrooms?fieldMask=participants { "1": { "id": 1, "title": "My Chat!", "description": "喇低賽", "participants": [] ⇐ 裡面有 10k 個鄉民,要處理很久 }, "2": { "id": 2, "title": "Your Chat!", "description": "低賽喇", "participants": [] ⇐ 裡面有 100k 個鄉民,要處理很久 } } Design: w/o participants in default GET /api/chatrooms <Default> { "1": { "id": 1, "title": "My Chat!", "description": "喇低賽", }, "2": { "id": 2, "title": "Your Chat!", "description": "低賽喇", } } 26 w/o participants
  • 27. 預設 = 製造了淺規則? ● 文件要明確說明,預設 fieldMask 的行為 ● 即使有文件,還是很容易誤解。 ● 不想讓使用者猜測哪些 fields 是預設的? ● 使用 asterick (“*”) 表示返回所有的 fields ● 取得資源使用預設 fieldMask 是用,但是更 新資源,Default FieldMask 就沒啥用 GET /api/chatrooms?fieldMask=* { "1": { "id": 1, "title": "My Chat!", "description": "喇低賽", "participants": [] ⇐ 裡面有 10k 個鄉民,要處理很久 } } GET /api/chatrooms?fieldMask=id,title { "1": { "id": 1, "title": "My Chat!", } } 27 個 人 觀 點 DesignA: 特定欄位的正向表列? Design B: 全部欄位的正向表列?
  • 28. 預設 = Policy (政策 / 慣例 / 文化 / 潛規則) ● 衝突來源 ● 怪異 ● 高雄式左轉 ● 習慣遲到 ● 公司的淺規則 ● 默契 ● 共識 ● 守法 ● 提前到、準時 ● 91APP 的政策 28 個 人 觀 點
  • 29. 預設 ● 專業領域 (Domain Know How) ● 企業文化 ● 鄉民文化 ● 潛在共識 ● 生態系 ○ .NET method name starts with uppercase ○ Java method name starts with lowercase 29 個 人 觀 點
  • 30. The goal of a default value is to do “the right thing” for the user. 啥叫做正確的事情? ← 這句話不夠具體 ● 給不同使用者,最必要的資訊。 ○ Chatroom 的參與者,需要怎樣的聊天室資訊? ○ Chatroom 的管理者,需要怎樣的聊天室資訊? ● 91APP 的專業判斷 => Domain Expert 必須思考的 => PO + Team ○ 對於 會員 (消費者) 而言,訂單 (Order) 要呈現什麼資訊? ○ 對於 91APP 的客戶 而言,訂單 (Order) 要呈現什麼資訊? ○ 對於 91APP 營管 而言,訂單 (Order) 要呈現什麼資訊? ○ 對於 91APP 合作夥伴 而言,訂單 (Order) 要呈現什麼資訊? 30 個 人 觀 點
  • 31. What does an unset field mask mean on a standard update method (using an HTTP PATCH method)? 8.3.5 Implicit field masks 31
  • 32. 32
  • 33. What does an unset field mask mean on a standard update method (using an HTTP PATCH method)? Most commonly, HTTP PATCH indicates an intent to update the resource with only the data provided in the body of the request. 8.3.5 Implicit field masks 33
  • 34. 8.3.5 Implicit field masks 34 PATCH/chatRooms/1 {"description":"Newdescription"} // 只更新 id=1 的 description
  • 35. ● dynamic data structure => object 型別 ○ ch5 提到的是 static data structure ● settings.test 有三種值: ○ “STRING_VALUE” ○ null ○ 不存在 ● 如果要刪除 settings.test 要怎麼做? ○ 不是 null ○ “undefined” 不是 JSON 資料型別 註:“undefined” 是語言層級的型別。 8.3.6 Updating dynamic data structures 35
  • 36. 36
  • 37. 8.3.6 Updating dynamic data structures ● settings.test 有三種值: ○ “STRING_VALUE” ○ null ○ 不存在 => undefined 的意思 ● 如果要刪除 settings.test 要怎麼做? ○ 不是 null ● “undefined” 不是 JSON 資料型別,是 JS 語言層級的型別。 ○ python 可能是 None 37
  • 39. 針對 “dynamic data structures” 的理解 Q_Q 39 個 人 觀 點 v1 v2
  • 40. 8.3.7 Invalid fields=> 參閱 CH24 Versioning and compatibility 40 個 人 觀 點 => ch24 v1 v2
  • 41. ● the goal is still quite limited: a. to minimize unnecessary data transfer and b. allow fine-grained modification of API resources. ● consider field masks and partial retrievals in particular as SQL-like querying tools to fetch specific data 8.4 Trade-offs 41
  • 43. Bo 先生:啥時候才有 GraphQL 的 Design Guideline 啊? 43
  • 44. 8.4.1 Universal support 44 ● NOT at all a requirement that every API must support partial retrieval. ● more an issue of concurrency than resource size and complexity
  • 45. 是否需要刻個 Libraries 實踐這些通用規則? C# 開發者表示:這還要問? Node.JS 開發者表示:我也要 Java 開發者表示:我也要 PHP 開發者表示:我。。。 45 個 人 觀 點
  • 46. 8.4.2 Alternative implementations ● JSON Patch (RFC6902), (npm) ● JSON Merge Patch (RFC7396), (npm) ● 哪裡有類似的概念:K8s 實作 ○ kubectl apply -f xxx.yaml 46
  • 47. 1. Partial retrieval is particularly important in cases where resources are large or clients consuming resource data have limited hardware. => POS 2. Partial updates are critical for fine-grained updates without worrying about conflicts. 3. Field masks, which support ways to address fields, nested fields in interfaces, and map keys, should be used to indicate the fields that should be retrieved or updated. 4. Field masks should NOT provide a mechanism to address items in array fields by their position or index in that field. 5. By default, field masks should assume a value of everything for partial retrievals and an implicit field mask (8.3.5) for partial updates. 6. If fields are invalid, they should be treated as though they do exist but have a value of undefined. Summary 47