How Uber "Go"es

How Uber "Go"es

Maintaining a large codebase with maximum readability and minimal overhead is hard. This is the story of how Go language went from a few enthusiastic Gophers to the most popular language for microservices at Uber. Learn where we failed, and how that led us to solutions that we think are pretty darn neat!

3558fb4000e2ba5bc2b3e7cf77668725?s=128

Elena Morozova

July 25, 2019
Tweet

Transcript

  1. None
  2. None
  3. None
  4. None
  5. • •

  6. None
  7. • •

  8. • • •

  9. None
  10. None
  11. level := os.Getenv("LOG_LEVEL") if level == "" { level =

    "info" } logger := log.New(os.Stdout, level, ...)
  12. logger level := os.Getenv("LOG_LEVEL") if level == "" { level

    = "info" } logger := log.New(os.Stdout, level, ...)
  13. logger config := struct{ ServiceName string }{} yaml.NewDecoder(file).Decode(&config)

  14. logger config config := struct{ ServiceName string }{} yaml.NewDecoder(file).Decode(&config)

  15. logger config server := lib.NewServer(...)

  16. logger config server server := lib.NewServer(...)

  17. logger config etc server ...

  18. logger config etc server ...

  19. logger config etc server ... tracer := tracing.New(logger, config) //

    * *jaegertracing.io server := lib.NewServer(lib.WithTracer(tracer))
  20. logger config etc server ... tracer := tracing.New(logger, config) //

    * *jaegertracing.io
  21. logger config etc *jaegertracing.io server tracer := tracing.New(logger, config) //

    *
  22. logger config etc *jaegertracing.io server tracer := tracing.New(logger, config) //

    * tracer
  23. logger config etc server server := lib.NewServer(lib.WithTracer(tracer)) tracer

  24. logger config etc server tracer

  25. logger config etc server ... logger config etc server ...

    ... logger config etc server tracer
  26. logger config etc logger ... ... ... tracer server

  27. None
  28. logger config etc logger ... ... ... tracer server

  29. logger config etc logger ... ... tracer server

  30. logger config etc logger ... ... tracer server

  31. logger config etc logger ... ... tracer server

  32. logger config etc logger ... ... tracer server

  33. DI GRAB & GO •

  34. None
  35. None
  36. None
  37. None
  38. None
  39. di.NewApp( di.defaults, // ... ).Run()

  40. di.NewApp( di.defaults, // ... ).Run()

  41. ...

  42. tracer := tracing.New(logger, config)

  43. tracer := tracing.New(logger, config)

  44. server := lib.NewServer( lib.WithTracer(tracer), )

  45. server := lib.NewServer( lib.WithTracer(tracer), )

  46. None
  47. ...

  48. ...

  49. ...

  50. ...

  51. ...

  52. ...

  53. ...

  54. ...

  55. ...

  56. ...

  57. ...

  58. package uberfx var Module = fx.Options( configfx, loggerfx, tracingfx, ...

    ) package main func main() { fx.New( uberfx.Module, ... ).Run() } github.com/uber-go/fx
  59. None
  60. REST

  61. REST gRPC

  62. REST gRPC

  63. Rewrite REST gRPC

  64. None
  65. REST gRPC

  66. REST gRPC

  67. Handlers . . .

  68. Controllers Handlers . . .

  69. Controllers Handlers . . .

  70. Controllers Handlers . . . http.Request pb.GetTrip ... Get Trip

    Request
  71. Controllers Handlers . . .

  72. Repositories Controllers Handlers . . .

  73. Repositories Controllers Gateways Handlers . . .

  74. Repositories . . .

  75. Repositories . . . Controllers List Users Request SELECT *

    FROM mysql;
  76. Repositories . . . Controllers List Users Request SELECT *

    FROM mysql; SELECT * FROM cassandra;
  77. Repositories . . . Controllers List Users Request SELECT *

    FROM mysql; SELECT * FROM cassandra;
  78. Repositories . . . Controllers List Users Request SELECT *

    FROM cassandra;
  79. Gateways . . .

  80. Gateways . . . Controllers Charge Payment Request http.Request

  81. Gateways . . . Controllers Charge Payment Request http.Request pb.Request

  82. Gateways . . . Controllers Charge Payment Request http.Request pb.Request

  83. Gateways . . . Controllers Charge Payment Request pb.Request

  84. Repositories Controllers Gateways Handlers . . .

  85. Repositories Controllers Gateways Handlers . . .

  86. Repositories Controllers Gateways Handlers . . .

  87. Repositories Controllers Gateways Handlers . . .

  88. Repositories Controllers Gateways Handlers . . .

  89. None
  90. None
  91. ├── app ├── controller ├── entity ├── gateway ├── gen

    │ └── [generated goodies] ├── handler └── repository $ glue new service
  92. • • ├── app ├── controller ├── entity ├── gateway

    ├── gen │ └── [generated goodies] ├── handler └── repository
  93. None
  94. None
  95. None
  96. None
  97. None
  98. None
  99. ...

  100. ...

  101. ...

  102. ...

  103. ...

  104. None
  105. ...

  106. ...

  107. ...

  108. ...

  109. ...

  110. ...

  111. None
  112. None
  113. None
  114. None
  115. None
  116. None
  117. None
  118. • •

  119. • • •

  120. • • •

  121. None
  122. • • • •

  123. • •

  124. https://github.com/MariaLetta/free-gophers-pack

  125. None