contributor > https://Gopherize.me << cute and ready to scale > Author of Go Programming Blueprints: Second Edition > Blog at matryer.com Follow me on Twitter @matryer
> I don't actually have to do that much > Go runs extremely quickly > If you build for horizontal scale, you can add nodes to meet demand > Platforms as a Service even do this for you
designed, a computer had a single core 2007: When Go was designed, multi-core computers cooperated at infinite horizontal scale > The Go Standard library comes with world class networking tools > We got HTTP/2 early and for free (zero code changes required)
balancer. If a client makes three requests, assume each request will be handled by a different node. This will change the way you think about: > In-process memory > Communication between processes
ServeHTTP(w http.ResponseWriter, r *http.Request) } type HandlerFunc func(w http.ResponseWriter, r *http.Request) func (fn HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) { fn(w, r) } > Real code from the standard library
routes() { s.router.Handle("/endpoint1", s.handleEndpointOne()) s.router.Handle("/endpoint2", s.handleEndpointTwo()) s.router.Handle("/endpoint3", s.handleEndpointThree()) } > One consistent place to look for routing
context.Context, w http.ResponseWriter, r *http.Request) error } > pro: Solve common problems once, and make your life easier > con: It makes it more difficult to use interchangably with other things written to support http.Handler
r *http.Request) { // Do stuff before h.ServeHTTP(w, r) // Do stuff after }) } http.Handle("/path", something(myHandler())) > It's handlers, all the way down > Use defer
{ if err := http.ListenAndServe(":8080", NewServer()); err != nil { log.Fatalln(err) } } > Package main > Use http.ListenAndServe > Start simple like this, and improve it later
NewServer()) } > Not package main, it is not really a Go tool > Use init function to bind to the catch-all endpoint > The router inside your Server will handle the rest
new HTTP request to your service will spin up a new instance > In other languages, this introduces a noticable delay > With Go, you have to check the logs to see if a new instance was started or not
database built for automatic scaling, high performance, and ease of application development. > Extremely fast > Has limitations, for good reasons like physics and computers
putting by key is strongly consistent > Querying is eventually consistent Three options: > Let Google Cloud Datastore generate keys for you > Use an int or a string