SlideShare a Scribd company logo
1
Go’s Context Library
By:
Smita Vijayakumar
Agenda
Introduction
-Context Management in
Distributed Systems
Go’s Context Library
Example Use case
Points to Watch Out For
2
1
2
3
4
3
Introduction
4
Distributed Data Flow
Request Processing
A B C
5
D E
RPC RPC RPC RPC
6
Go Context
• Defines *Context* type
• Carries request-scoped
values:
- Deadlines
- Cancellation signals
- Others
• Works across API
boundaries
- Also between processes
7
Details
type Context interface {
Done() <-chan struct{}

Err() error

Deadline() (deadline time.Time, ok bool)

Value(key interface{}) interface{}

}
8
1. Distributed Tracing
2. Request Cancellation
3. Context value
Primary
Use Cases
9
struct ContextValue {
requestID string
}
Example 1 - Distributed Tracing
10
Types of
Context Nodes
1. Background Node
2. Value Node
3. Cancellable Node
4. TODO() Node
Example -
A = context.Background()
B, cancelB = context.WithCancel(A)
C = context.WithValue(A, “C Key”, “C”)
D = context.WithValue(A, “D Key”, “D”)
E, cancelE = context.WithTimeout(B, timeout)
..
Background
Context
A
With
Value
C
With
Cancel
B
With
Value
D
With
Timeout
E
With
Value
F
With
Value
G
With
Value
11
H
With
Value
I
With
Value
J
Types - A Context Tree
12
package userid
const ctxKey string = “UserID”
func SetContextValue(ctx context.Context, id int) context.Context
{
return context.WithValue(ctx, ctxKey, id)
}
func GetContextValue(ctx context.Context) (int, bool) {
id, ok := ctx.Value(ctxKey).(int)
return id, ok
}
Example 2 - UTIL Package
13
package request
func startRequest(event *event.Event, timeout time.Duration) error {
ctx, cancel :=
context.WithTimeout(context.Background(), timeout)
defer cancel()
//…
ctx = util.SetContextValue(ctx, id)
status, err := processor.Server(ctx, event)
//…
}
Example 2 - Cancellable Request - Set the Context
14
package request
func startRequest(event *event.Event, timeout time.Duration) error {
ctx, cancel :=
context.WithTimeout(context.Background(), timeout)
defer cancel()
//…
ctx = util.SetContextValue(ctx, id)
status, err := processor.Server(ctx, event)
//…
}
Example 2 - Cancellable Request - Set the Context
15
package request
func startRequest(event *event.Event, timeout time.Duration) error {
ctx, cancel :=
context.WithTimeout(context.Background(), timeout)
defer cancel()
//…
ctx = util.SetContextValue(ctx, id)
status, err := processor.Server(ctx, event)
//…
}
Example 2 - Cancellable Request - Set the Context
16
package processor
func Server(ctx context.Context, event *event.Event) error {
if id, ok := util.FromContext(ctx); !ok {

return errors.New(“Not a valid ID to process”)

}
p := make(chan error, 1)
go func(ctx context.Context, id int,
event *event.Event) {
p <- processEvent(ctx, id, event)
}()
Example 2 - Cancellable Request – Get and Handle Context
17
package processor
func Server(ctx context.Context, event *event.Event) error {
if id, ok := util.FromContext(ctx); !ok {

return errors.New(“Not a valid ID to process”)

}
p := make(chan error, 1)
go func(ctx context.Context, id int,
event *event.Event) {
p <- processEvent(ctx, id, event)
}()
Example 2 - Cancellable Request – Get and Handle Context
18
//continued
select {
case <-ctx.Done():
//…
return ctx.Err()
case err := <-p
return err
}
}
Example 2 - Cancellable Request – Get and Handle Context
19
1. Ease of handling multiple,
concurrent requests
Summary -
Use Cases In
Distributed
System
2. Flow Traceability and
Fingerprinting
3. Time Sensitive and Cancellable
Request Processing
4. Ease of sending context
information
20
Remember!
21
Remember… For larger systems, complexity is
the downside
Code Complexity:
22
Difficult to actually implement
passing cancellable signals
downstream
Inter-Process Boundaries:
Remember…
23
Don’t store context variables
inside structures
Garbage Collection:
Remember…
24
Holding the right context node
Querying:
Remember…
25
Thank you!
For any queries:
Smita Vijayakumar smita@exotel.in
Ad

More Related Content

What's hot (20)

Smart Contract programming 101 with Solidity #PizzaHackathon
Smart Contract programming 101 with Solidity #PizzaHackathonSmart Contract programming 101 with Solidity #PizzaHackathon
Smart Contract programming 101 with Solidity #PizzaHackathon
Sittiphol Phanvilai
 
No More Deadlocks; Asynchronous Programming in .NET
No More Deadlocks; Asynchronous Programming in .NETNo More Deadlocks; Asynchronous Programming in .NET
No More Deadlocks; Asynchronous Programming in .NET
Filip Ekberg
 
Dex and Uniswap
Dex and UniswapDex and Uniswap
Dex and Uniswap
Gene Leybzon
 
Correcting Common .NET Async/Await Mistakes
Correcting Common .NET Async/Await MistakesCorrecting Common .NET Async/Await Mistakes
Correcting Common .NET Async/Await Mistakes
Brandon Minnick, MBA
 
Using Cerberus and PySpark to validate semi-structured datasets
Using Cerberus and PySpark to validate semi-structured datasetsUsing Cerberus and PySpark to validate semi-structured datasets
Using Cerberus and PySpark to validate semi-structured datasets
Bartosz Konieczny
 
Fetch data from form
Fetch data from formFetch data from form
Fetch data from form
Shahriar Malik
 
Minion pool - a worker pool for nodejs
Minion pool - a worker pool for nodejsMinion pool - a worker pool for nodejs
Minion pool - a worker pool for nodejs
Marcelo Gornstein
 
Apache Spark in your likeness - low and high level customization
Apache Spark in your likeness - low and high level customizationApache Spark in your likeness - low and high level customization
Apache Spark in your likeness - low and high level customization
Bartosz Konieczny
 
FwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.jsFwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.js
Timur Shemsedinov
 
Monitoring und Metriken im Wunderland
Monitoring und Metriken im WunderlandMonitoring und Metriken im Wunderland
Monitoring und Metriken im Wunderland
D
 
Apache Spark Structured Streaming + Apache Kafka = ♡
Apache Spark Structured Streaming + Apache Kafka = ♡Apache Spark Structured Streaming + Apache Kafka = ♡
Apache Spark Structured Streaming + Apache Kafka = ♡
Bartosz Konieczny
 
Do something in 5 with gas 9-copy between databases with oauth2
Do something in 5 with gas 9-copy between databases with oauth2Do something in 5 with gas 9-copy between databases with oauth2
Do something in 5 with gas 9-copy between databases with oauth2
Bruce McPherson
 
Async Microservices with Twitter's Finagle
Async Microservices with Twitter's FinagleAsync Microservices with Twitter's Finagle
Async Microservices with Twitter's Finagle
Vladimir Kostyukov
 
Blockchain and smart contracts day 2
Blockchain and smart contracts day 2Blockchain and smart contracts day 2
Blockchain and smart contracts day 2
Gene Leybzon
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass Slides
Nir Kaufman
 
What is row level isolation on cassandra
What is row level isolation on cassandraWhat is row level isolation on cassandra
What is row level isolation on cassandra
Kazutaka Tomita
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the web
Michiel Borkent
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015
Michiel Borkent
 
dSS API by example
dSS API by exampledSS API by example
dSS API by example
digitalSTROM.org
 
Hands on with smart contracts 2. Presentation for the Blockchain Applications...
Hands on with smart contracts 2. Presentation for the Blockchain Applications...Hands on with smart contracts 2. Presentation for the Blockchain Applications...
Hands on with smart contracts 2. Presentation for the Blockchain Applications...
Gene Leybzon
 
Smart Contract programming 101 with Solidity #PizzaHackathon
Smart Contract programming 101 with Solidity #PizzaHackathonSmart Contract programming 101 with Solidity #PizzaHackathon
Smart Contract programming 101 with Solidity #PizzaHackathon
Sittiphol Phanvilai
 
No More Deadlocks; Asynchronous Programming in .NET
No More Deadlocks; Asynchronous Programming in .NETNo More Deadlocks; Asynchronous Programming in .NET
No More Deadlocks; Asynchronous Programming in .NET
Filip Ekberg
 
Correcting Common .NET Async/Await Mistakes
Correcting Common .NET Async/Await MistakesCorrecting Common .NET Async/Await Mistakes
Correcting Common .NET Async/Await Mistakes
Brandon Minnick, MBA
 
Using Cerberus and PySpark to validate semi-structured datasets
Using Cerberus and PySpark to validate semi-structured datasetsUsing Cerberus and PySpark to validate semi-structured datasets
Using Cerberus and PySpark to validate semi-structured datasets
Bartosz Konieczny
 
Minion pool - a worker pool for nodejs
Minion pool - a worker pool for nodejsMinion pool - a worker pool for nodejs
Minion pool - a worker pool for nodejs
Marcelo Gornstein
 
Apache Spark in your likeness - low and high level customization
Apache Spark in your likeness - low and high level customizationApache Spark in your likeness - low and high level customization
Apache Spark in your likeness - low and high level customization
Bartosz Konieczny
 
FwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.jsFwDays 2021: Metarhia Technology Stack for Node.js
FwDays 2021: Metarhia Technology Stack for Node.js
Timur Shemsedinov
 
Monitoring und Metriken im Wunderland
Monitoring und Metriken im WunderlandMonitoring und Metriken im Wunderland
Monitoring und Metriken im Wunderland
D
 
Apache Spark Structured Streaming + Apache Kafka = ♡
Apache Spark Structured Streaming + Apache Kafka = ♡Apache Spark Structured Streaming + Apache Kafka = ♡
Apache Spark Structured Streaming + Apache Kafka = ♡
Bartosz Konieczny
 
Do something in 5 with gas 9-copy between databases with oauth2
Do something in 5 with gas 9-copy between databases with oauth2Do something in 5 with gas 9-copy between databases with oauth2
Do something in 5 with gas 9-copy between databases with oauth2
Bruce McPherson
 
Async Microservices with Twitter's Finagle
Async Microservices with Twitter's FinagleAsync Microservices with Twitter's Finagle
Async Microservices with Twitter's Finagle
Vladimir Kostyukov
 
Blockchain and smart contracts day 2
Blockchain and smart contracts day 2Blockchain and smart contracts day 2
Blockchain and smart contracts day 2
Gene Leybzon
 
Nestjs MasterClass Slides
Nestjs MasterClass SlidesNestjs MasterClass Slides
Nestjs MasterClass Slides
Nir Kaufman
 
What is row level isolation on cassandra
What is row level isolation on cassandraWhat is row level isolation on cassandra
What is row level isolation on cassandra
Kazutaka Tomita
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the web
Michiel Borkent
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015
Michiel Borkent
 
Hands on with smart contracts 2. Presentation for the Blockchain Applications...
Hands on with smart contracts 2. Presentation for the Blockchain Applications...Hands on with smart contracts 2. Presentation for the Blockchain Applications...
Hands on with smart contracts 2. Presentation for the Blockchain Applications...
Gene Leybzon
 

Viewers also liked (20)

Setting A Culture of Technical Excellence
Setting A Culture of Technical ExcellenceSetting A Culture of Technical Excellence
Setting A Culture of Technical Excellence
Exotel
 
Working at Exotel
Working at ExotelWorking at Exotel
Working at Exotel
Exotel
 
Exotel For Last Mile Logistics
Exotel For Last Mile LogisticsExotel For Last Mile Logistics
Exotel For Last Mile Logistics
Exotel
 
Cloud Communication for E-commerce & Last Mile Logistics
Cloud Communication for E-commerce & Last Mile LogisticsCloud Communication for E-commerce & Last Mile Logistics
Cloud Communication for E-commerce & Last Mile Logistics
Exotel
 
Monitor PowerKVM using Ganglia, Nagios
Monitor PowerKVM using Ganglia, NagiosMonitor PowerKVM using Ganglia, Nagios
Monitor PowerKVM using Ganglia, Nagios
Pradeep Kumar
 
One-click Hadoop Cluster Deployment on OpenPOWER Systems
One-click Hadoop Cluster Deployment on OpenPOWER SystemsOne-click Hadoop Cluster Deployment on OpenPOWER Systems
One-click Hadoop Cluster Deployment on OpenPOWER Systems
Pradeep Kumar
 
Gluster containers!
Gluster containers!Gluster containers!
Gluster containers!
Humble Chirammal
 
Comment travailler avec les logiciels Open Source
Comment travailler avec les logiciels Open SourceComment travailler avec les logiciels Open Source
Comment travailler avec les logiciels Open Source
Christian Charreyre
 
Meetup Systemd vs sysvinit
Meetup Systemd vs sysvinitMeetup Systemd vs sysvinit
Meetup Systemd vs sysvinit
Christian Charreyre
 
BibBase Linked Data Triplification Challenge 2010 Presentation
BibBase Linked Data Triplification Challenge 2010 PresentationBibBase Linked Data Triplification Challenge 2010 Presentation
BibBase Linked Data Triplification Challenge 2010 Presentation
Reynold Xin
 
ERTS 2008 - Using Linux for industrial projects
ERTS 2008 - Using Linux for industrial projectsERTS 2008 - Using Linux for industrial projects
ERTS 2008 - Using Linux for industrial projects
Christian Charreyre
 
ERTS 2008 - Using Linux for industrial projects
ERTS 2008 - Using Linux for industrial projectsERTS 2008 - Using Linux for industrial projects
ERTS 2008 - Using Linux for industrial projects
Christian Charreyre
 
Créer une distribution Linux embarqué professionnelle avec Yocto Project
Créer une distribution Linux embarqué professionnelle avec Yocto ProjectCréer une distribution Linux embarqué professionnelle avec Yocto Project
Créer une distribution Linux embarqué professionnelle avec Yocto Project
Christian Charreyre
 
Open Embedded un framework libre pour assurer la cohérence de son projet
Open Embedded un framework libre pour assurer la cohérence de son projetOpen Embedded un framework libre pour assurer la cohérence de son projet
Open Embedded un framework libre pour assurer la cohérence de son projet
Christian Charreyre
 
Présentation Yocto - SophiaConf 2015
Présentation Yocto - SophiaConf 2015Présentation Yocto - SophiaConf 2015
Présentation Yocto - SophiaConf 2015
Christian Charreyre
 
Yocto une solution robuste pour construire des applications à fort contenu ap...
Yocto une solution robuste pour construire des applications à fort contenu ap...Yocto une solution robuste pour construire des applications à fort contenu ap...
Yocto une solution robuste pour construire des applications à fort contenu ap...
Christian Charreyre
 
OS libres pour l'IoT - Zephyr
OS libres pour l'IoT - ZephyrOS libres pour l'IoT - Zephyr
OS libres pour l'IoT - Zephyr
Christian Charreyre
 
Autotools
AutotoolsAutotools
Autotools
Christian Charreyre
 
Gluster Contenarized Storage for Cloud Applications
Gluster Contenarized Storage for Cloud ApplicationsGluster Contenarized Storage for Cloud Applications
Gluster Contenarized Storage for Cloud Applications
Humble Chirammal
 
Using heka
Using hekaUsing heka
Using heka
Exotel
 
Setting A Culture of Technical Excellence
Setting A Culture of Technical ExcellenceSetting A Culture of Technical Excellence
Setting A Culture of Technical Excellence
Exotel
 
Working at Exotel
Working at ExotelWorking at Exotel
Working at Exotel
Exotel
 
Exotel For Last Mile Logistics
Exotel For Last Mile LogisticsExotel For Last Mile Logistics
Exotel For Last Mile Logistics
Exotel
 
Cloud Communication for E-commerce & Last Mile Logistics
Cloud Communication for E-commerce & Last Mile LogisticsCloud Communication for E-commerce & Last Mile Logistics
Cloud Communication for E-commerce & Last Mile Logistics
Exotel
 
Monitor PowerKVM using Ganglia, Nagios
Monitor PowerKVM using Ganglia, NagiosMonitor PowerKVM using Ganglia, Nagios
Monitor PowerKVM using Ganglia, Nagios
Pradeep Kumar
 
One-click Hadoop Cluster Deployment on OpenPOWER Systems
One-click Hadoop Cluster Deployment on OpenPOWER SystemsOne-click Hadoop Cluster Deployment on OpenPOWER Systems
One-click Hadoop Cluster Deployment on OpenPOWER Systems
Pradeep Kumar
 
Comment travailler avec les logiciels Open Source
Comment travailler avec les logiciels Open SourceComment travailler avec les logiciels Open Source
Comment travailler avec les logiciels Open Source
Christian Charreyre
 
BibBase Linked Data Triplification Challenge 2010 Presentation
BibBase Linked Data Triplification Challenge 2010 PresentationBibBase Linked Data Triplification Challenge 2010 Presentation
BibBase Linked Data Triplification Challenge 2010 Presentation
Reynold Xin
 
ERTS 2008 - Using Linux for industrial projects
ERTS 2008 - Using Linux for industrial projectsERTS 2008 - Using Linux for industrial projects
ERTS 2008 - Using Linux for industrial projects
Christian Charreyre
 
ERTS 2008 - Using Linux for industrial projects
ERTS 2008 - Using Linux for industrial projectsERTS 2008 - Using Linux for industrial projects
ERTS 2008 - Using Linux for industrial projects
Christian Charreyre
 
Créer une distribution Linux embarqué professionnelle avec Yocto Project
Créer une distribution Linux embarqué professionnelle avec Yocto ProjectCréer une distribution Linux embarqué professionnelle avec Yocto Project
Créer une distribution Linux embarqué professionnelle avec Yocto Project
Christian Charreyre
 
Open Embedded un framework libre pour assurer la cohérence de son projet
Open Embedded un framework libre pour assurer la cohérence de son projetOpen Embedded un framework libre pour assurer la cohérence de son projet
Open Embedded un framework libre pour assurer la cohérence de son projet
Christian Charreyre
 
Présentation Yocto - SophiaConf 2015
Présentation Yocto - SophiaConf 2015Présentation Yocto - SophiaConf 2015
Présentation Yocto - SophiaConf 2015
Christian Charreyre
 
Yocto une solution robuste pour construire des applications à fort contenu ap...
Yocto une solution robuste pour construire des applications à fort contenu ap...Yocto une solution robuste pour construire des applications à fort contenu ap...
Yocto une solution robuste pour construire des applications à fort contenu ap...
Christian Charreyre
 
Gluster Contenarized Storage for Cloud Applications
Gluster Contenarized Storage for Cloud ApplicationsGluster Contenarized Storage for Cloud Applications
Gluster Contenarized Storage for Cloud Applications
Humble Chirammal
 
Using heka
Using hekaUsing heka
Using heka
Exotel
 
Ad

Similar to #Gophercon Talk by Smita Vijayakumar - Go's Context Library (20)

Online Meetup: Why should container system / platform builders care about con...
Online Meetup: Why should container system / platform builders care about con...Online Meetup: Why should container system / platform builders care about con...
Online Meetup: Why should container system / platform builders care about con...
Docker, Inc.
 
用 Go 語言打造多台機器 Scale 架構
用 Go 語言打造多台機器 Scale 架構用 Go 語言打造多台機器 Scale 架構
用 Go 語言打造多台機器 Scale 架構
Bo-Yi Wu
 
Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30) Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30)
Paco de la Cruz
 
gRPC in Go
gRPC in GogRPC in Go
gRPC in Go
Almog Baku
 
GraphQL Bangkok Meetup 2.0
GraphQL Bangkok Meetup 2.0GraphQL Bangkok Meetup 2.0
GraphQL Bangkok Meetup 2.0
Tobias Meixner
 
Architecting Alive Apps
Architecting Alive AppsArchitecting Alive Apps
Architecting Alive Apps
Jorge Ortiz
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
Bo-Yi Wu
 
Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)
Paco de la Cruz
 
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
GDG Devfest 2019 - Build go kit microservices at kubernetes with easeGDG Devfest 2019 - Build go kit microservices at kubernetes with ease
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
KAI CHU CHUNG
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
GeeksLab Odessa
 
Codable routing
Codable routingCodable routing
Codable routing
Pushkar Kulkarni
 
Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)
Paco de la Cruz
 
Intro to Node
Intro to NodeIntro to Node
Intro to Node
Aaron Stannard
 
分散式系統
分散式系統分散式系統
分散式系統
acksinkwung
 
Streaming Data with scalaz-stream
Streaming Data with scalaz-streamStreaming Data with scalaz-stream
Streaming Data with scalaz-stream
GaryCoady
 
Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at Pinterest
Pavan Chitumalla
 
A deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio moduleA deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio module
Saúl Ibarra Corretgé
 
外部環境への依存をテストする
外部環境への依存をテストする外部環境への依存をテストする
外部環境への依存をテストする
Shunsuke Maeda
 
Context Information Management in IoT enabled smart systems - the basics
Context Information Management in IoT enabled smart systems - the basicsContext Information Management in IoT enabled smart systems - the basics
Context Information Management in IoT enabled smart systems - the basics
Fernando Lopez Aguilar
 
Live Streaming & Server Sent Events
Live Streaming & Server Sent EventsLive Streaming & Server Sent Events
Live Streaming & Server Sent Events
tkramar
 
Online Meetup: Why should container system / platform builders care about con...
Online Meetup: Why should container system / platform builders care about con...Online Meetup: Why should container system / platform builders care about con...
Online Meetup: Why should container system / platform builders care about con...
Docker, Inc.
 
用 Go 語言打造多台機器 Scale 架構
用 Go 語言打造多台機器 Scale 架構用 Go 語言打造多台機器 Scale 架構
用 Go 語言打造多台機器 Scale 架構
Bo-Yi Wu
 
Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30) Azure Durable Functions (2019-03-30)
Azure Durable Functions (2019-03-30)
Paco de la Cruz
 
GraphQL Bangkok Meetup 2.0
GraphQL Bangkok Meetup 2.0GraphQL Bangkok Meetup 2.0
GraphQL Bangkok Meetup 2.0
Tobias Meixner
 
Architecting Alive Apps
Architecting Alive AppsArchitecting Alive Apps
Architecting Alive Apps
Jorge Ortiz
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
Bo-Yi Wu
 
Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)Azure Durable Functions (2019-04-27)
Azure Durable Functions (2019-04-27)
Paco de la Cruz
 
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
GDG Devfest 2019 - Build go kit microservices at kubernetes with easeGDG Devfest 2019 - Build go kit microservices at kubernetes with ease
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
KAI CHU CHUNG
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
GeeksLab Odessa
 
Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)
Paco de la Cruz
 
Streaming Data with scalaz-stream
Streaming Data with scalaz-streamStreaming Data with scalaz-stream
Streaming Data with scalaz-stream
GaryCoady
 
Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at Pinterest
Pavan Chitumalla
 
A deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio moduleA deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio module
Saúl Ibarra Corretgé
 
外部環境への依存をテストする
外部環境への依存をテストする外部環境への依存をテストする
外部環境への依存をテストする
Shunsuke Maeda
 
Context Information Management in IoT enabled smart systems - the basics
Context Information Management in IoT enabled smart systems - the basicsContext Information Management in IoT enabled smart systems - the basics
Context Information Management in IoT enabled smart systems - the basics
Fernando Lopez Aguilar
 
Live Streaming & Server Sent Events
Live Streaming & Server Sent EventsLive Streaming & Server Sent Events
Live Streaming & Server Sent Events
tkramar
 
Ad

More from Exotel (9)

Exotel cost of moving to cloud
Exotel cost of moving to cloudExotel cost of moving to cloud
Exotel cost of moving to cloud
Exotel
 
(Webinar) E-commerce delivery lifecycle - How to streamline communication
(Webinar) E-commerce delivery lifecycle - How to streamline communication(Webinar) E-commerce delivery lifecycle - How to streamline communication
(Webinar) E-commerce delivery lifecycle - How to streamline communication
Exotel
 
Introduction to Go programming
Introduction to Go programmingIntroduction to Go programming
Introduction to Go programming
Exotel
 
Exotel - Cloud telephony, Business phone system experts
Exotel - Cloud telephony, Business phone system expertsExotel - Cloud telephony, Business phone system experts
Exotel - Cloud telephony, Business phone system experts
Exotel
 
E-Commerce Call Trends in India Report
E-Commerce Call Trends in India ReportE-Commerce Call Trends in India Report
E-Commerce Call Trends in India Report
Exotel
 
To Sell Is Human: The Surprising Truth About Moving Others - a summary
To Sell Is Human: The Surprising Truth About Moving Others - a summaryTo Sell Is Human: The Surprising Truth About Moving Others - a summary
To Sell Is Human: The Surprising Truth About Moving Others - a summary
Exotel
 
Exotel Culture Code
Exotel Culture CodeExotel Culture Code
Exotel Culture Code
Exotel
 
Customer Development @ SLP Mumbai by Ruchir
Customer Development @ SLP Mumbai by RuchirCustomer Development @ SLP Mumbai by Ruchir
Customer Development @ SLP Mumbai by Ruchir
Exotel
 
Nasscom Product Conclave - How to get your first 20 customers
Nasscom Product Conclave - How to get your first 20 customersNasscom Product Conclave - How to get your first 20 customers
Nasscom Product Conclave - How to get your first 20 customers
Exotel
 
Exotel cost of moving to cloud
Exotel cost of moving to cloudExotel cost of moving to cloud
Exotel cost of moving to cloud
Exotel
 
(Webinar) E-commerce delivery lifecycle - How to streamline communication
(Webinar) E-commerce delivery lifecycle - How to streamline communication(Webinar) E-commerce delivery lifecycle - How to streamline communication
(Webinar) E-commerce delivery lifecycle - How to streamline communication
Exotel
 
Introduction to Go programming
Introduction to Go programmingIntroduction to Go programming
Introduction to Go programming
Exotel
 
Exotel - Cloud telephony, Business phone system experts
Exotel - Cloud telephony, Business phone system expertsExotel - Cloud telephony, Business phone system experts
Exotel - Cloud telephony, Business phone system experts
Exotel
 
E-Commerce Call Trends in India Report
E-Commerce Call Trends in India ReportE-Commerce Call Trends in India Report
E-Commerce Call Trends in India Report
Exotel
 
To Sell Is Human: The Surprising Truth About Moving Others - a summary
To Sell Is Human: The Surprising Truth About Moving Others - a summaryTo Sell Is Human: The Surprising Truth About Moving Others - a summary
To Sell Is Human: The Surprising Truth About Moving Others - a summary
Exotel
 
Exotel Culture Code
Exotel Culture CodeExotel Culture Code
Exotel Culture Code
Exotel
 
Customer Development @ SLP Mumbai by Ruchir
Customer Development @ SLP Mumbai by RuchirCustomer Development @ SLP Mumbai by Ruchir
Customer Development @ SLP Mumbai by Ruchir
Exotel
 
Nasscom Product Conclave - How to get your first 20 customers
Nasscom Product Conclave - How to get your first 20 customersNasscom Product Conclave - How to get your first 20 customers
Nasscom Product Conclave - How to get your first 20 customers
Exotel
 

Recently uploaded (20)

860556374-10280271.pptx PETROLEUM COKE CALCINATION PLANT
860556374-10280271.pptx PETROLEUM COKE CALCINATION PLANT860556374-10280271.pptx PETROLEUM COKE CALCINATION PLANT
860556374-10280271.pptx PETROLEUM COKE CALCINATION PLANT
Pierre Celestin Eyock
 
UNIT 5 Software Engineering sem 6 EIOV.pdf
UNIT 5  Software Engineering sem 6 EIOV.pdfUNIT 5  Software Engineering sem 6 EIOV.pdf
UNIT 5 Software Engineering sem 6 EIOV.pdf
sikarwaramit089
 
Espresso PD Official MP_eng Version.pptx
Espresso PD Official MP_eng Version.pptxEspresso PD Official MP_eng Version.pptx
Espresso PD Official MP_eng Version.pptx
NingChacha1
 
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Journal of Soft Computing in Civil Engineering
 
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic AlgorithmDesign Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Journal of Soft Computing in Civil Engineering
 
AI-Powered Data Management and Governance in Retail
AI-Powered Data Management and Governance in RetailAI-Powered Data Management and Governance in Retail
AI-Powered Data Management and Governance in Retail
IJDKP
 
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
22PCOAM16 ML Unit 3 Full notes PDF & QB.pdf
Guru Nanak Technical Institutions
 
7- Bearing..pptx 7- Bearing..pptx7- Bearing..pptx
7- Bearing..pptx 7- Bearing..pptx7- Bearing..pptx7- Bearing..pptx 7- Bearing..pptx7- Bearing..pptx
7- Bearing..pptx 7- Bearing..pptx7- Bearing..pptx
abdokhattab2015
 
A Study of Bank Line Shifting of the Selected Reach of Jamuna River Using Mul...
A Study of Bank Line Shifting of the Selected Reach of Jamuna River Using Mul...A Study of Bank Line Shifting of the Selected Reach of Jamuna River Using Mul...
A Study of Bank Line Shifting of the Selected Reach of Jamuna River Using Mul...
Journal of Soft Computing in Civil Engineering
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
DeFAIMint | 🤖Mint to DeFAI. Vibe Trading as NFT
DeFAIMint | 🤖Mint to DeFAI. Vibe Trading as NFTDeFAIMint | 🤖Mint to DeFAI. Vibe Trading as NFT
DeFAIMint | 🤖Mint to DeFAI. Vibe Trading as NFT
Kyohei Ito
 
Construction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil EngineeringConstruction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil Engineering
Lavish Kashyap
 
[PyCon US 2025] Scaling the Mountain_ A Framework for Tackling Large-Scale Te...
[PyCon US 2025] Scaling the Mountain_ A Framework for Tackling Large-Scale Te...[PyCon US 2025] Scaling the Mountain_ A Framework for Tackling Large-Scale Te...
[PyCon US 2025] Scaling the Mountain_ A Framework for Tackling Large-Scale Te...
Jimmy Lai
 
IPC-7711D-7721D_ EN 2023 TOC Rework, Modification and Repair of Electronic As...
IPC-7711D-7721D_ EN 2023 TOC Rework, Modification and Repair of Electronic As...IPC-7711D-7721D_ EN 2023 TOC Rework, Modification and Repair of Electronic As...
IPC-7711D-7721D_ EN 2023 TOC Rework, Modification and Repair of Electronic As...
ssuserd9338b
 
Domain1_Security_Principles --(My_Notes)
Domain1_Security_Principles --(My_Notes)Domain1_Security_Principles --(My_Notes)
Domain1_Security_Principles --(My_Notes)
efs14135
 
Automatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and BeyondAutomatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and Beyond
NU_I_TODALAB
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
22PCOAM16 Unit 3 Session 23 Different ways to Combine Classifiers.pptx
22PCOAM16 Unit 3 Session 23  Different ways to Combine Classifiers.pptx22PCOAM16 Unit 3 Session 23  Different ways to Combine Classifiers.pptx
22PCOAM16 Unit 3 Session 23 Different ways to Combine Classifiers.pptx
Guru Nanak Technical Institutions
 
ldr darkness sensor circuit.pptx for engineers
ldr darkness sensor circuit.pptx for engineersldr darkness sensor circuit.pptx for engineers
ldr darkness sensor circuit.pptx for engineers
PravalikaChidurala
 
860556374-10280271.pptx PETROLEUM COKE CALCINATION PLANT
860556374-10280271.pptx PETROLEUM COKE CALCINATION PLANT860556374-10280271.pptx PETROLEUM COKE CALCINATION PLANT
860556374-10280271.pptx PETROLEUM COKE CALCINATION PLANT
Pierre Celestin Eyock
 
UNIT 5 Software Engineering sem 6 EIOV.pdf
UNIT 5  Software Engineering sem 6 EIOV.pdfUNIT 5  Software Engineering sem 6 EIOV.pdf
UNIT 5 Software Engineering sem 6 EIOV.pdf
sikarwaramit089
 
Espresso PD Official MP_eng Version.pptx
Espresso PD Official MP_eng Version.pptxEspresso PD Official MP_eng Version.pptx
Espresso PD Official MP_eng Version.pptx
NingChacha1
 
AI-Powered Data Management and Governance in Retail
AI-Powered Data Management and Governance in RetailAI-Powered Data Management and Governance in Retail
AI-Powered Data Management and Governance in Retail
IJDKP
 
7- Bearing..pptx 7- Bearing..pptx7- Bearing..pptx
7- Bearing..pptx 7- Bearing..pptx7- Bearing..pptx7- Bearing..pptx 7- Bearing..pptx7- Bearing..pptx
7- Bearing..pptx 7- Bearing..pptx7- Bearing..pptx
abdokhattab2015
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
DeFAIMint | 🤖Mint to DeFAI. Vibe Trading as NFT
DeFAIMint | 🤖Mint to DeFAI. Vibe Trading as NFTDeFAIMint | 🤖Mint to DeFAI. Vibe Trading as NFT
DeFAIMint | 🤖Mint to DeFAI. Vibe Trading as NFT
Kyohei Ito
 
Construction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil EngineeringConstruction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil Engineering
Lavish Kashyap
 
[PyCon US 2025] Scaling the Mountain_ A Framework for Tackling Large-Scale Te...
[PyCon US 2025] Scaling the Mountain_ A Framework for Tackling Large-Scale Te...[PyCon US 2025] Scaling the Mountain_ A Framework for Tackling Large-Scale Te...
[PyCon US 2025] Scaling the Mountain_ A Framework for Tackling Large-Scale Te...
Jimmy Lai
 
IPC-7711D-7721D_ EN 2023 TOC Rework, Modification and Repair of Electronic As...
IPC-7711D-7721D_ EN 2023 TOC Rework, Modification and Repair of Electronic As...IPC-7711D-7721D_ EN 2023 TOC Rework, Modification and Repair of Electronic As...
IPC-7711D-7721D_ EN 2023 TOC Rework, Modification and Repair of Electronic As...
ssuserd9338b
 
Domain1_Security_Principles --(My_Notes)
Domain1_Security_Principles --(My_Notes)Domain1_Security_Principles --(My_Notes)
Domain1_Security_Principles --(My_Notes)
efs14135
 
Automatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and BeyondAutomatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and Beyond
NU_I_TODALAB
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
22PCOAM16 Unit 3 Session 23 Different ways to Combine Classifiers.pptx
22PCOAM16 Unit 3 Session 23  Different ways to Combine Classifiers.pptx22PCOAM16 Unit 3 Session 23  Different ways to Combine Classifiers.pptx
22PCOAM16 Unit 3 Session 23 Different ways to Combine Classifiers.pptx
Guru Nanak Technical Institutions
 
ldr darkness sensor circuit.pptx for engineers
ldr darkness sensor circuit.pptx for engineersldr darkness sensor circuit.pptx for engineers
ldr darkness sensor circuit.pptx for engineers
PravalikaChidurala
 

#Gophercon Talk by Smita Vijayakumar - Go's Context Library

  • 2. Agenda Introduction -Context Management in Distributed Systems Go’s Context Library Example Use case Points to Watch Out For 2 1 2 3 4
  • 5. Request Processing A B C 5 D E RPC RPC RPC RPC
  • 6. 6 Go Context • Defines *Context* type • Carries request-scoped values: - Deadlines - Cancellation signals - Others • Works across API boundaries - Also between processes
  • 7. 7 Details type Context interface { Done() <-chan struct{}
 Err() error
 Deadline() (deadline time.Time, ok bool)
 Value(key interface{}) interface{}
 }
  • 8. 8 1. Distributed Tracing 2. Request Cancellation 3. Context value Primary Use Cases
  • 9. 9 struct ContextValue { requestID string } Example 1 - Distributed Tracing
  • 10. 10 Types of Context Nodes 1. Background Node 2. Value Node 3. Cancellable Node 4. TODO() Node
  • 11. Example - A = context.Background() B, cancelB = context.WithCancel(A) C = context.WithValue(A, “C Key”, “C”) D = context.WithValue(A, “D Key”, “D”) E, cancelE = context.WithTimeout(B, timeout) .. Background Context A With Value C With Cancel B With Value D With Timeout E With Value F With Value G With Value 11 H With Value I With Value J Types - A Context Tree
  • 12. 12 package userid const ctxKey string = “UserID” func SetContextValue(ctx context.Context, id int) context.Context { return context.WithValue(ctx, ctxKey, id) } func GetContextValue(ctx context.Context) (int, bool) { id, ok := ctx.Value(ctxKey).(int) return id, ok } Example 2 - UTIL Package
  • 13. 13 package request func startRequest(event *event.Event, timeout time.Duration) error { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() //… ctx = util.SetContextValue(ctx, id) status, err := processor.Server(ctx, event) //… } Example 2 - Cancellable Request - Set the Context
  • 14. 14 package request func startRequest(event *event.Event, timeout time.Duration) error { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() //… ctx = util.SetContextValue(ctx, id) status, err := processor.Server(ctx, event) //… } Example 2 - Cancellable Request - Set the Context
  • 15. 15 package request func startRequest(event *event.Event, timeout time.Duration) error { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() //… ctx = util.SetContextValue(ctx, id) status, err := processor.Server(ctx, event) //… } Example 2 - Cancellable Request - Set the Context
  • 16. 16 package processor func Server(ctx context.Context, event *event.Event) error { if id, ok := util.FromContext(ctx); !ok {
 return errors.New(“Not a valid ID to process”)
 } p := make(chan error, 1) go func(ctx context.Context, id int, event *event.Event) { p <- processEvent(ctx, id, event) }() Example 2 - Cancellable Request – Get and Handle Context
  • 17. 17 package processor func Server(ctx context.Context, event *event.Event) error { if id, ok := util.FromContext(ctx); !ok {
 return errors.New(“Not a valid ID to process”)
 } p := make(chan error, 1) go func(ctx context.Context, id int, event *event.Event) { p <- processEvent(ctx, id, event) }() Example 2 - Cancellable Request – Get and Handle Context
  • 18. 18 //continued select { case <-ctx.Done(): //… return ctx.Err() case err := <-p return err } } Example 2 - Cancellable Request – Get and Handle Context
  • 19. 19 1. Ease of handling multiple, concurrent requests Summary - Use Cases In Distributed System 2. Flow Traceability and Fingerprinting 3. Time Sensitive and Cancellable Request Processing 4. Ease of sending context information
  • 21. 21 Remember… For larger systems, complexity is the downside Code Complexity:
  • 22. 22 Difficult to actually implement passing cancellable signals downstream Inter-Process Boundaries: Remember…
  • 23. 23 Don’t store context variables inside structures Garbage Collection: Remember…
  • 24. 24 Holding the right context node Querying: Remember…
  • 25. 25 Thank you! For any queries: Smita Vijayakumar smita@exotel.in
  翻译: