building scalable backends with go

20
Building Scalable Backends With Go Shiju Varghese

Upload: shiju-varghese

Post on 15-Jan-2017

255 views

Category:

Technology


5 download

TRANSCRIPT

Page 1: Building Scalable Backends with Go

BuildingScalableBackendsWithGo

ShijuVarghese

Page 2: Building Scalable Backends with Go

AboutMe

• ConsultingSolutionsArchitect• FocusedonGoandGoogleCloud

@shijucv|https://medium.com/@shijuvar

Page 3: Building Scalable Backends with Go
Page 4: Building Scalable Backends with Go

Agenda

• IntroductiontoGo• Goasalanguageforbuildingscalablebackendsystems• Demo-RESTfulAPIwithGo

Page 5: Building Scalable Backends with Go

GoasaLanguageforBuildingScalableBackendSystems

Page 6: Building Scalable Backends with Go

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

Page 7: Building Scalable Backends with Go

Gocanbedescribedinthreewords:Simple,MinimalandPragmatic.

Page 8: Building Scalable Backends with Go

» MinimalisticlanguagewithPragmaticDesign» AStaticTypeLanguagewithHighProductivity» ConcurrencyisaBuilt-inFeature» GoCompilesProgramsQuickly» GoisaGeneral-PurposeLanguage» GoMobileProject

IntroducingGo

Page 9: Building Scalable Backends with Go

GoEcosystem

» Golanguage» Golibraries» Gotooling

Page 10: Building Scalable Backends with Go

WhyGo?

» ConcurrencyandCommunicatingSequentialProcesses(CSP)

» ModernC» PragmatismandDeveloperproductivity» GoCommunity» Gosuccessstories-Docker,Kubernetes,CoreOSandsuccessfulimplementationsofMicroservices

» LanguagefortheeraofCloud,MicroservicesandContainers

Page 11: Building Scalable Backends with Go

BuildingHTTPServers

Page 12: Building Scalable Backends with Go

net/httpPackage

» ProvidesHTTPclientandserverimplementations» AllowsyoutobuildHTTPserversinGo» Providescomposabilityandextensibility

Page 13: Building Scalable Backends with Go

ProcessingHTTPRequests

» ServeMux-HTTPrequestmultiplexer» Handler-ServeHTTPrequests

Page 14: Building Scalable Backends with Go

http.HandlerInterface

type Handler interface { ServeHTTP(ResponseWriter, *Request) }

» ServeHTTPrequests.» HandlersareresponsibleforwritingheadersandbodiesintoHTTPresponses.

Page 15: Building Scalable Backends with Go

packagemain

import("fmt""net/http")

funchello(whttp.ResponseWriter,r*http.Request){fmt.Fprintf(w,"Helloworld!")}

funcmain(){http.HandleFunc("/",hello)http.ListenAndServe(":8000",nil)}

AnHTTPServer

Page 16: Building Scalable Backends with Go

HTTPMiddleware

» Pluggableandself-containedpieceofcodethatwrapswebapplicationhandlers.

» Componentsthatworkasanotherlayerintherequesthandlingcycle,whichcanexecutesomelogicbeforeorafterexecutingapplicationhandlers.

» Greatforimplementingcross-cuttingconcerns:Authentication,authorization,caching,loggingetc.

Page 17: Building Scalable Backends with Go

funcloggingHandler(nexthttp.Handler)http.Handler{returnhttp.HandlerFunc(func(whttp.ResponseWriter,r*http.Request){start:=time.Now()log.Printf("Started%s%s",r.Method,r.URL.Path)next.ServeHTTP(w,r)log.Printf("Completed%sin%v",r.URL.Path,time.Since(start))})}

//ApplyingMiddlewarehttp.Handle("/",loggingHandler(indexHandler))http.Handle("/about",loggingHandler(aboutHandler))

Page 18: Building Scalable Backends with Go

Demo-RESTAPIwithGoandMongoDB

Source:https://github.com/shijuvar/go-web/tree/master/taskmanager

Page 19: Building Scalable Backends with Go

» GoisagreatstackforbuildingscalablebackendsystemsandMicroservices.

» GoisagreatstackforbuildingRESTfulAPIs.

KeyTakeaways