Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Revolutionising Retail with Go

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Revolutionising Retail with Go

In a competitive market, Sainsbury’s is on a technology transformation process which involves the adoption of Go and a journey to cloud based distributed systems at scale.

The talk covers why we are increasingly choosing Go to solve these problems, architectural decisions, common mistakes, technology stack and how this delivers highly available, distributed systems that need to interact with legacy systems.

Avatar for Charlie Smith

Charlie Smith

August 19, 2016

More Decks by Charlie Smith

Other Decks in Programming

Transcript

  1. service := micro.NewService( micro.Name("service.stock"), micro.Version("latest"), micro.Flags( cli.StringFlag{ Name: "config_file_path", EnvVar:

    "CONFIG_PATH", Usage: "Config file path", }, ), micro.Action(func(c *cli.Context) { config.File = c.String("config_file_path") }), ) proto.RegisterStockHandler(service.Server(), &handlers.Stock{}) ...
  2. // Set up eventsHandler := events.NewEventHandler() go eventsHandler.Init() ..... //

    Receive event ..... eventsHandler.Receive <- events.Event{ Ref: &foo, Data: map[string]interface{}{ "foo": foo, "bar": bar, }, }
  3. // Receive websocket connection .... conn := &events.Connection{ Ref: sku,

    Ws: ws, } eventsHandler.RegisterEvent(conn) <-conn.Done
  4. func NewEventHandler() *Handler { return &Handler{ Receive: make(chan Event), Store:

    make(map[string]map[*websocket.Conn]*Connection), } }
  5. func (h *Handler) Init() { for { event := <-h.Receive

    if event.Ref == nil { log.Printf("Ref not provided... %+v", event) continue } go h.BroadcastEvent(event, *event.Ref) go h.BroadcastEvent(event, "") } }
  6. func (h *Handler) BroadcastEvent(event Event, ref string) { h.eventsLock.RLock() defer

    h.eventsLock.RUnlock() js, err := json.Marshal(event.Data) if err != nil { return } for _, conn := range h.Store[ref] { err := websocket.JSON.Send(conn.Ws, string(js)) if err != nil { conn.Ws.Close() return err } } }