Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Design Patterns in Micro-services architectures & Gilmour

467 views

Published on

Gilmour is a framework for writing micro-services that exchange data over non-http transports. Talk looks at Design Patterns of a service oriented architecture, like Request-Response, Signal-Slots, Service Discovery, Load Balancing, Error detection and how Gilmour addresses those.

Published in: Software
  • Be the first to comment

Design Patterns in Micro-services architectures & Gilmour

  1. 1. GILMOUR DESIGN PATTERNS IN MICRO-SERVICES ARCHITECTURES &
  2. 2. ABOUT WHO AM I? ▸ twitter: @meson10 ▸ mailto: piyush@piyushverma.net ▸ piyushverma.net
  3. 3. SOA (VS SERVERS) WHAT ARE SERVICES ▸ Logical Entities ▸ Independent ▸ Comprised of more services ▸ Multiple servers for load and tolerance ▸ Scalability ▸ Flexibility
  4. 4. TO ERR IS HUMAN, TO BLAME IT ON SOMEONE IS MANAGEMENT POTENTIAL. - Someone on Internet WHY?
  5. 5. WHO DUN IT? WHY SERVICES? ▸ Software Problem ▸ Scalability ▸ Management Problem ▸ Authority ▸ Responsibility.
  6. 6. DESIGN PATTERNS
  7. 7. REQUEST RESPONSE
  8. 8. REQUEST RESPONSE CALLER SERVICE HELLO? ALOHA!WRONG NUMBER Message { “Data”nterface{} `json:"data"` //Actual Payload Code int `json:"code"` //Response code if this is a response. This uses HTTP error codes Sender string `json:"sender"` //Origin of the request (unique for each request) } SENDER_ID CODE
  9. 9. REQUEST data := G.NewMessage().SetData("hello?") resp := g.Request(“echo", data, nil) var msg string req.Data(&msg); fmt.Println("Echoclient: received", msg) opts := G.NewHandlerOpts().SetGroup("exclusive") g.ReplyTo("echo", func(req *G.Request, resp *G.Message) { var msg string req.Data(&msg) resp.SetData(fmt.Sprintf("Pong %v", msg)) }, opts) RESPONSE REQUEST
  10. 10. ASYNC / SIGNAL-SLOTS
  11. 11. ASYNC: SIGNALS AND SLOTS Slots Signal ITEM.BUY.500 ITEM.BUY.* ITEM.BUY.* ITEM.BUY.* GROUP: PUSH_MSG FP SCALING PUSH MESSAGE SERVERPUSH MESSAGE SERVER WEB GILMOUR EMAIL NOTIFIER SMS NOTIFIER PUSH MESSAGE SERVER ITEM PURCHASED VIP ITEM PURCHASED ITEM.BUY.420
  12. 12. ASYNC: SLOTS g := G.Get(redis) g.Slot("example.log", func(req *G.Request) { var msg string req.Data(&msg) log.Println(req.Sender(), "->", msg) }) g.Start() g.Signal("example.log", G.NewMessage().SetData("log message emitted")) SIGNAL RECEIVER / SLOT
  13. 13. SIGNAL-SLOT VS. REQUEST-RESPONSE
  14. 14. ASYNC VS SYNC WHAT TO USE WHEN? ▸ Request-Response ▸ Confirmed delivery. ▸ Response or Error Guaranteed. ▸ HTTP Like. ▸ Sender responsible for errors.
  15. 15. ASYNC VS SYNC WHAT TO USE WHEN? ▸ Signal-Slots ▸ UDP-like. ▸ Broadcasting ▸ Wildcard topics ▸ Unreliable delivery. ▸ Receiver responsible for errors.
  16. 16. SERVICE DISCOVERY & LOAD BALANCING
  17. 17. NOTIFICATION SERVER 1 REPLICATED LOAD BALANCER X.Y.Y.Z?CALLER SERVICE REGISTER I, AM HEALTHY? NOTIFICATION SERVER 2 NOTIFICATION SERVER 3
  18. 18. NOTIFICATION SERVER 2 GILMOUR MANAGER.NOTIFICATION NOTIFICATION SERVER 1 NOTIFICATION SERVER 3 MANAGER.NOTIFICATION MANAGER.NOTIFICATION CALLER SERVICE MANAGER.NOTIFICATION {“NOTIFICATION”: “DATA”}
  19. 19. DISCOVERY AND LOAD BALANCING LOOK MA, NO SERVICE DISCOVERY ▸ Gilmour works on Redis Subscriber Publisher. ▸ No querying discovery process. ▸ Call service and not servers.
  20. 20. DISCOVERY AND LOAD BALANCING LOOK MA, NO LOAD BALANCING ▸ Has Capacity, Will Serve. ▸ Message delivered to one and all. ▸ Fittest node acquires lock first.
  21. 21. ERRORS: DETECTION & HANDLING
  22. 22. GILMOUR ERRORS ERROR DETECTION ▸ Timeouts ▸ server side - execution timed out. ▸ client side - response too late ▸ confirm_subscribers
  23. 23. GILMOUR ERRORS WEB GILMOUR EMAIL NOTIFIER SMS NOTIFIER PUSH MESSAGE Slots ERROR REPORTER Signal
  24. 24. GILMOUR ERRORS CALLER SERVICE HELLO? WRONG NUMBER SENDER_ID CODE ERROR REPORTER type gilmourError struct { topic string //topic to which the request was sent requestData string //request payload userData string //implementation dependent information sender string //sender from the request timestamp string //timestamp of error backtrace interface{} //backtrace of the error code int //response code (non-200) }
  25. 25. GILMOUR ERRORS ERROR HANDLING ▸ Ignore ▸ Publish ▸ Queue func main() { redis := backends.MakeRedis("127.0.0.1:6379", "pass") g := G.Get(redis) //g.SetErrorPolicy(protocol.ErrorPolicyQueue) //g.SetErrorPolicy(protocol.ErrorPolicyIgnore) g.SetErrorPolicy(protocol.ErrorPolicyPublish) }
  26. 26. GILMOUR ERRORS ERROR SAMPLE
  27. 27. OPS: MONITORING
  28. 28. OPS: MONITORING SERVERS ▸ Log forwarding & aggregation ▸ Error Reporting ▸ Server and Health Monitoring
  29. 29. OPS: MONITORING SERVICES ▸ Are the services servicing? ▸ Do services have spare capacity? ▸ Do services respond in time? ▸ Health Bulletin: github.com/gilmour-libs/health-bulletin
  30. 30. OPS: MONITORING
  31. 31. OPS: MONITORING
  32. 32. OPS: MONITORING Feb 23 12:25:14 qa-next-backend-manager0.datascale.io gilmour_health: D, [2016-02-23T06:55:12.930435 #22111] DEBUG -- : Ensuring topics have at least one subscriber Feb 23 12:25:14 qa-next-backend-manager0.datascale.io gilmour_health: D, [2016-02-23T06:55:12.931160 #22111] DEBUG -- : Ensuring that gilmour servers respond to health ping Feb 23 12:26:14 qa-next-backend-manager0.datascale.io backend_manager: D, [2016-02-23T06:56:12.932775 #9605] DEBUG -- : Executing handler for gilmour.health.ip-10-0-0-146-pid-9605-uuid-9d0484dd-08e5-4ec3- a3e4-9a109634712b from 2881867d41f24228b462b9eff0b7e88e 2016-04-03 00:06:56 d0e4ea929645600e2fa97657091613a4 -> Cleared VPC jenkins-backend-manager-pipeline-qa-17 2016-04-03 00:06:56 d0e4ea929645600e2fa97657091613a4 -> Clearing databag customer_jenkins-backend-manager- pipeline-qa-17_config::vpc_config 2016-04-03 00:06:57 d0e4ea929645600e2fa97657091613a4 -> Deleted data_bag[customer_jenkins-backend-manager- pipeline-qa-17_config] 2016-04-03 00:06:57 d0e4ea929645600e2fa97657091613a4 -> Clearing DNS entries 2016-04-03 00:07:00 d0e4ea929645600e2fa97657091613a4 -> Cleaning Chef environment 2016-04-03 00:07:01 d0e4ea929645600e2fa97657091613a4 -> Deleted customer_jenkins-backend-manager-pipeline- qa-17 REQUEST LOGGING
  33. 33. 
 COMPOSITION
  34. 34. COMPOSITION ▸ compose - service1 | service2 | composition3 ▸ andand - service1 && service2 && composition3 ▸ oror - service1 || composition2 || service3 ▸ batch ▸ (service1; service2; service3) > out ▸ service1; composition2; service3 > out ▸ parallel ▸ lambda functions
  35. 35. COMPOSITION popular := g.NewParallel( g.NewRequestComposition("example.popular3"), g.NewRequestComposition("example.popular4"), ) batch := g.NewPipe( g.NewRequestComposition("example.fetch"), g.NewRequestComposition("example.words"), g.NewRequestComposition("example.count"), popular, ) data := G.NewMessage() data.SetData("https://s3.amazonaws.com/ds-data-sample/test.txt") msg := <-batch.Execute(data)
  36. 36. COMPOSITION popular := g.NewParallel( g.NewRequestComposition("example.popular3"), g.NewRequestComposition(“example.popular4"), g.NewRequestComposition("example.popular5"), ) batch := g.NewPipe( g.NewRequestComposition("example.fetch"), g.NewRequestComposition("example.words"), g.NewRequestComposition("example.stopfilter"), g.NewRequestComposition("example.count"), popular, &MyComposer{}, ) 
 data := G.NewMessage() data.SetData("https://s3.amazonaws.com/ds-data-sample/test.txt") msg := <-batch.Execute(data)
  37. 37. COMPOSITION batch := e.NewPipe( e.NewRequest("weather.fetch"), e.NewRequest("weather.group"), e.NewParallel( e.NewPipe( e.NewLambda(monthLambda("jan")), e.NewParallel( e.NewRequest("weather.min"), e.NewRequest("weather.max"), ), ), e.NewPipe( e.NewLambda(monthLambda("feb")), e.NewParallel( e.NewRequest("weather.min"), e.NewRequest("weather.max"), ), ), ), )
  38. 38. 
 TALK IS CHEAP: SHOW SOME DEMO
  39. 39. EXAMPLES: ECHO SERVERS & CLIENT
  40. 40. SAMPLE TEXT
  41. 41. EXAMPLES: POPULAR WORD COUNT ▸ Given ▸ A S3 URL pointing to a file that has (lot of) random text. ▸ Goal ▸ Eliminate stop words from the file. ▸ Find most popular 3, 4, and 5 letter words. ▸ Find these in parallel.
  42. 42. EXAMPLES: WEATHER AGGREGATION ▸ Output ▸ Popular 3 letter words: [way, for] ▸ Popular 4 letter words: [Text, copy] ▸ Popular 5 letter words: [Blind, blind]
  43. 43. EXAMPLES: COMPOSITION
  44. 44. EXAMPLES: WEATHER AGGREGATION ▸ Given ▸ Weather data as per hour, per day, per month of form: ▸ {"Day": 10, "Month": "jan", "Hour": 13, "Degrees": 56}
  45. 45. EXAMPLES: WEATHER AGGREGATION ▸ Goal ▸ For the months of Jan & Feb ▸ Find the maximum temperature recorded. ▸ Find the minimum temperature recorded. ▸ If possible do 3a and 3b in parallel, and in parallel for both months
  46. 46. EXAMPLES: WEATHER AGGREGATION ▸ Output ▸ Temperature on 19th Feb at 2100 hours was 50ºF ▸ Temperature on 21st Feb at 0500 hours was 94ºF ▸ Temperature on 19th Jan at 1900 hours was 50ºF ▸ Temperature on 17th Jan at 2200 hours was 94ºF
  47. 47. EXAMPLES: COMPOSITION
  48. 48. GILMOUR RECAP ▸ Library only; no external process. ▸ No Load Balancer ▸ No Service Discovery ▸ Signal, Slots. ▸ Broadcast, Wildcard Topics. ▸ Exclusion groups. ▸ Sync - Request, Reply ▸ Error and Health Monitoring - HealthBulletin. ▸ Failure Detection ▸ Composition - Real micro-services. ▸ No message persistence.
  49. 49. GILMOUR CREDITS & LINKS ▸ Aditya Godbole ▸ aa@gdbl.me ▸ Datascale.IO ▸ datascale.io ▸ Repository ▸ github.com/gilmour-libs

×