Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

Building a full-stack app with Golang and Google Cloud Platform in one week

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Wird geladen in …3
×

Hier ansehen

1 von 120 Anzeige

Building a full-stack app with Golang and Google Cloud Platform in one week

Herunterladen, um offline zu lesen

The talk will cover how to effectively build a production-ready, full-stack app with Golang and GCP under time constraints. I'll discuss how to approach making quick and sound technical decisions and how to apply modern software engineering practices for end-to-end apps. The presentation shows, in an opinionated and "meme-ful" way, various lessons learned, tools, and key takeaways for cloud environments.

The talk will cover how to effectively build a production-ready, full-stack app with Golang and GCP under time constraints. I'll discuss how to approach making quick and sound technical decisions and how to apply modern software engineering practices for end-to-end apps. The presentation shows, in an opinionated and "meme-ful" way, various lessons learned, tools, and key takeaways for cloud environments.

Anzeige
Anzeige

Weitere Verwandte Inhalte

Diashows für Sie (20)

Ähnlich wie Building a full-stack app with Golang and Google Cloud Platform in one week (20)

Anzeige

Aktuellste (20)

Building a full-stack app with Golang and Google Cloud Platform in one week

  1. 1. Memes in the Cloud – Building a full-stack app with Golang and Google Cloud Platform in one week Dr. Felix Raab | Head of Engineering @ KI Labs Munich | ki-labs.com f.raab@kigroup.de | medium.com/@fe9lix
  2. 2. SCOPE OF TALK
  3. 3. SCOPE OF TALK Case Study Project idea and journey for an MVP finished within one week
  4. 4. SCOPE OF TALK Case Study Project idea and journey for an MVP finished within one week Software Engineering for Cloud Apps The “full” stack: Frontend, Backend, Build, Deployment, Logging… Towards the end of the talk: Software Engineering practices in Go
  5. 5. SCOPE OF TALK Case Study Project idea and journey for an MVP finished within one week Software Engineering for Cloud Apps The “full” stack: Frontend, Backend, Build, Deployment, Logging… Towards the end of the talk: Software Engineering practices in Go Memes At the heart of the app itself – consequently, Memes to illustrate some opinionated views
  6. 6. BACK AT MY PREVIOUS EMPLOYER… Hours claiming – trying not get “shitlisted”… because the boss would be notified!
  7. 7. Idea – Every Friday… Schedule an hours claim reminder mail containing a meme, to myself.
  8. 8. FIRST: HOW TO CHOOSE A CLOUD? …when you can start from scratch – no corporate constraints, no restrictions, no Frankfurt.
  9. 9. LOOK AT THE HISTORY OF CLOUD COMPANIES
  10. 10. LOOK AT THE HISTORY OF CLOUD COMPANIES
  11. 11. LOOK AT THE HISTORY OF CLOUD COMPANIES
  12. 12. LOOK AT THE HISTORY OF CLOUD COMPANIES
  13. 13. LOOK AT THE HISTORY OF CLOUD COMPANIES MICROSOFT AZURE
  14. 14. LOOK AT THE HISTORY OF CLOUD COMPANIES MICROSOFT AZURE AMAZON WEB SERVICES
  15. 15. LOOK AT THE HISTORY OF CLOUD COMPANIES MICROSOFT AZURE AMAZON WEB SERVICES GOOGLE CLOUD PLATFORM
  16. 16. LOOK AT THE HISTORY OF CLOUD COMPANIES MICROSOFT AZURE AMAZON WEB SERVICES GOOGLE CLOUD PLATFORM Enterprise
  17. 17. LOOK AT THE HISTORY OF CLOUD COMPANIES MICROSOFT AZURE AMAZON WEB SERVICES GOOGLE CLOUD PLATFORM Enterprise Ops
  18. 18. LOOK AT THE HISTORY OF CLOUD COMPANIES MICROSOFT AZURE AMAZON WEB SERVICES GOOGLE CLOUD PLATFORM Enterprise Ops S(R)E
  19. 19. –Brave New Geek “Multi-Cloud Is a Trap” https://bravenewgeek.com/multi-cloud-is-a-trap/
  20. 20. WORKS LIKE YOU WOULD EXPECT IT…
  21. 21. WORKS LIKE YOU WOULD EXPECT IT… Service Offerings used to build MemeMail
  22. 22. WORKS LIKE YOU WOULD EXPECT IT… Service Offerings used to build MemeMail More on that later…
  23. 23. WORKS LIKE YOU WOULD EXPECT IT… Service Offerings used to build MemeMail More on that later… API access, permissions, config…
  24. 24. WORKS LIKE YOU WOULD EXPECT IT… Service Offerings used to build MemeMail More on that later… CI/CD API access, permissions, config…
  25. 25. WORKS LIKE YOU WOULD EXPECT IT… Service Offerings used to build MemeMail More on that later… CI/CD Database (NoSQL document store) API access, permissions, config…
  26. 26. WORKS LIKE YOU WOULD EXPECT IT… Service Offerings used to build MemeMail More on that later… CI/CD Database (NoSQL document store) Object Storage (Blobs…) API access, permissions, config…
  27. 27. WORKS LIKE YOU WOULD EXPECT IT… Service Offerings used to build MemeMail More on that later… CI/CD Database (NoSQL document store) Object Storage (Blobs…) Task Queue (with scheduling!) API access, permissions, config…
  28. 28. WORKS LIKE YOU WOULD EXPECT IT… Service Offerings used to build MemeMail More on that later… CI/CD Database (NoSQL document store) Object Storage (Blobs…) Task Queue (with scheduling!) Logging… API access, permissions, config…
  29. 29. The Frontend – Diving into the world of JavaScript? https://exceptionnotfound.net/big-ball-of-mud-the-daily-software-anti-pattern/
  30. 30. THE FULLSTACK IN GO – SO HOW ABOUT WEBASSEMBLY (WASM)?
  31. 31. NO! BECAUSE…
  32. 32. NO! BECAUSE…
  33. 33. NO! BECAUSE… Readability, Debugging, Size…
 (but maybe in the future)
  34. 34. NO WEBASSEMBLY. MAYBE ELM THEN?
  35. 35. NO! BECAUSE… Learning curve, different paradigm, transpiling to JS, libraries… – remember, we have one week to finish!
  36. 36. VANILLA JS (ES 6)! 
 BUT WHICH FRAMEWORK?
  37. 37. RESIST THE TEMPTATION TO…
  38. 38. RESIST THE TEMPTATION TO…
  39. 39. RESIST THE TEMPTATION TO… Also, do not use Github Stars as your only criterion! Popularity is one thing…
  40. 40. HOW TO CHOOSE
  41. 41. HOW TO CHOOSE 1) Does it solve your problem in a simple way? Rendering the frontend and adding interaction without sprinkling jQuery calls throughout your code base.
  42. 42. HOW TO CHOOSE 1) Does it solve your problem in a simple way? Rendering the frontend and adding interaction without sprinkling jQuery calls throughout your code base. 2) Look at the quality of the documentation! Because you need to read it and be able to understand it – quickly!
  43. 43. VUE.JS SEEMS TO MATCH. BUT WHICH ARCHITECTURE?
  44. 44. SO MANY APPROACHES… …MVVM, Flux, Redux, SAM, ELM Architecture…? What is the essence?
  45. 45. STATE MUTATION
  46. 46. STATE MUTATION Take notice when somebody tells you that you should or can entirely avoid mutating state.
  47. 47. MUTATING STATE. HERE’S HOW…
  48. 48. MUTATING STATE. HERE’S HOW… 1) Put your entire app state into a single model Avoid primitive obsession – use proper objects! This is your single source of truth.
  49. 49. MUTATING STATE. HERE’S HOW… 1) Put your entire app state into a single model Avoid primitive obsession – use proper objects! This is your single source of truth. 2) Dispatch Actions from the UI to trigger a state mutation Do not yet mutate the state in the action itself! Actions are intents with payloads.
  50. 50. MUTATING STATE. HERE’S HOW… 1) Put your entire app state into a single model Avoid primitive obsession – use proper objects! This is your single source of truth. 2) Dispatch Actions from the UI to trigger a state mutation Do not yet mutate the state in the action itself! Actions are intents with payloads. 3) Accept or reject the state mutation in your model At the end of your (async.) action, “commit” / “propose” a new value to the model.
  51. 51. MUTATING STATE. HERE’S HOW… 1) Put your entire app state into a single model Avoid primitive obsession – use proper objects! This is your single source of truth. 2) Dispatch Actions from the UI to trigger a state mutation Do not yet mutate the state in the action itself! Actions are intents with payloads. 3) Accept or reject the state mutation in your model At the end of your (async.) action, “commit” / “propose” a new value to the model. 4) Update the UI when the state changes Derive the state to render from your model, e.g. by UI bindings.
  52. 52. VUEX.JS KIND OF SUPPORTS THAT PATTERN
  53. 53. –Ryan Dahl “[...] if you’re building a server, I can’t imagine using anything other than ” THE BACKEND.
  54. 54. HOW TO BUILD?
  55. 55. HOW TO BUILD? Go 1.11 Because Go Modules!
  56. 56. HOW TO BUILD? Go 1.11 Because Go Modules! Docker To be flexible with Go versions
 Multi-stage build!
  57. 57. HOW TO BUILD? Go 1.11 Because Go Modules! Docker To be flexible with Go versions
 Multi-stage build! entr + Makefile No Rake, Grunt, Gulp, NPM, Yarn – Makefile + Bash Script fine! Check entrproject.org
  58. 58. APP ENGINE – START SIMPLE
  59. 59. APP ENGINE – START SIMPLE
  60. 60. APP ENGINE – START SIMPLE App Engine Flex You can migrate to Kubernetes (GKE) later if you wish to – but for your MVP, don’t waste time managing a cluster.
  61. 61. APP ENGINE – START SIMPLE App Engine Flex You can migrate to Kubernetes (GKE) later if you wish to – but for your MVP, don’t waste time managing a cluster. Use defaults Start with App Engine default options and auto-scaling. Nobody knows how much traffic you will get. Watch and see what happens.
  62. 62. SEPARATE THE FRONTEND AND BACKEND?
  63. 63. YES AND NO!
  64. 64. YES AND NO! Expose your services as API to the frontend Frontend is rendered via a Go template. On that rendered page, a Single Page App can run in memory and call your backend API. Use Go templates for other static pages. Makes routing easier.
  65. 65. YES AND NO! Expose your services as API to the frontend Frontend is rendered via a Go template. On that rendered page, a Single Page App can run in memory and call your backend API. Use Go templates for other static pages. Makes routing easier. But no need to create two deployment units No need for premature optimisation (scaling). One Go binary is simpler than two Go binaries! 
 Static assets are loaded from the file system in your container.
  66. 66. CI/CD
  67. 67. CI/CD Google Cloud Build Will trigger and deploy when you push to your Git repo. Maintaining your own Jenkins server and setting up a build pipeline can be more time-consuming than you might think.
  68. 68. CI/CD Google Cloud Build Will trigger and deploy when you push to your Git repo. Maintaining your own Jenkins server and setting up a build pipeline can be more time-consuming than you might think. App Engine Deployment Straightforward versioning and service concept via DNS – version.service.appname Promoting app to production, traffic splitting etc. – 
 supported out of the box
  69. 69. The cloud can be mean and slow.
  70. 70. PLAYGROUNDS SAVE TIME Create a GCP “Playground” project Got stuck with Cloud Datastore (vs. Cloud Firestore) and 
 Cloud Tasks (only certain EU region). Led me to test service offerings first via playground.
  71. 71. WHICH ARCHITECTURE – ONIONS AND HEXAGONS?
  72. 72. SO MANY LAYERS AND CONCEPTS Also, ask yourself : Is there a rich domain? Or are you really building a CRUD app?
  73. 73. Take notice when nobody tells you to separate functionality into lots and lots of really small methods and delegating objects.
  74. 74. A QUESTION OF PHILOSOPHIES?
  75. 75. A QUESTION OF PHILOSOPHIES?
  76. 76. A QUESTION OF PHILOSOPHIES? Robert Martin (Uncle Bob) http://2017.agilesummit.gr/speakers/uncle-bob/
  77. 77. A QUESTION OF PHILOSOPHIES? John Ousterhout https://www.youtube.com/watch?v=bmSAYlu0NcY Robert Martin (Uncle Bob) http://2017.agilesummit.gr/speakers/uncle-bob/
  78. 78. DEEP VS SHALLOW MODULES
  79. 79. DEEP VS SHALLOW MODULES Shallow ModuleDeep module Interface Functionality
  80. 80. DEEP VS SHALLOW MODULES Shallow Module “The best modules are deep: they allow a lot of functionality to be accessed through a simple interface. A shallow module is one with a relatively complex interface, but not much functionality: it doesn’t hide much complexity.” 
 – From A Philosophy of Software Design, John Ousterhout Deep module Interface Functionality
  81. 81. EXAMPLE OF A DEEP MODULE Meme Image Generation Package “meme”, image.go: Simple interface, a lot of functionality.
  82. 82. PASS-THROUGH CODE TENDS TO BE SHALLOW – BUT HOW MUCH SEPARATION?
  83. 83. Separate the outside from the inside Kind of onion, just fewer layers
  84. 84. Separate the outside from the inside Kind of onion, just fewer layers Outside (package http) Protocol, routing (gorilla/mux), handlers
  85. 85. Separate the outside from the inside Kind of onion, just fewer layers Outside (package http) Protocol, routing (gorilla/mux), handlers Inside (package meme) Core, your actual (business) functionality
  86. 86. WHAT ABOUT INTERFACES?
  87. 87. IMPLICIT INTERFACE CONFORMANCE
  88. 88. IMPLICIT INTERFACE CONFORMANCE Awesome Golang feature, but here…
  89. 89. IMPLICIT INTERFACE CONFORMANCE Awesome Golang feature, but here…
  90. 90. IMPLICIT INTERFACE CONFORMANCE Awesome Golang feature, but here…
  91. 91. IMPLICIT INTERFACE CONFORMANCE Awesome Golang feature, but here… To be able to inject a different implementation, you would need to either create an interface that mirrors the datastore api or create a generic interface -> shallow wrapper
  92. 92. IMPLICIT INTERFACE CONFORMANCE Awesome Golang feature, but here… To be able to inject a different implementation, you would need to either create an interface that mirrors the datastore api or create a generic interface -> shallow wrapper Have a look at google/go-cloud for unstructured binary storage (supports GCP and AWS)
  93. 93. STRONGER ARGUMENT FOR AN INTERFACE?
  94. 94. STRONGER ARGUMENT FOR AN INTERFACE? Logging Needed almost everywhere! But Go’s default logging has limitations.
  95. 95. STRONGER ARGUMENT FOR AN INTERFACE? Logging Needed almost everywhere! But Go’s default logging has limitations. Even better: Structured Logging Implicit conformance to uber-go/zap for structured logging
  96. 96. STRONGER ARGUMENT FOR AN INTERFACE? Logging Needed almost everywhere! But Go’s default logging has limitations. Even better: Structured Logging Implicit conformance to uber-go/zap for structured logging
  97. 97. HOW TO HANDLE CROSS- CUTTING CONCERNS…?
  98. 98. CONTEXT OBJECT PATTERN
  99. 99. CONTEXT OBJECT PATTERN Reduce coupling of method parameters Instead of passing the logger through method parameters, pass a Go context object through middleware.
  100. 100. CONTEXT OBJECT PATTERN Reduce coupling of method parameters Instead of passing the logger through method parameters, pass a Go context object through middleware.
  101. 101. CONTEXT OBJECT PATTERN Reduce coupling of method parameters Instead of passing the logger through method parameters, pass a Go context object through middleware. Still not ideal, but good enough? Also see: https://medium.com/@gosamv/using-gos-context-library-for-logging-4a8feea26690
  102. 102. FINALLY, BEING CONSISTENT…
  103. 103. FINALLY, BEING CONSISTENT…
  104. 104. FINALLY, BEING CONSISTENT… Strong Consistency After creating, the user should see the most recent list of meme reminders 
 (strong consistency supported by Cloud Datastore)
  105. 105. FINALLY, BEING CONSISTENT… Strong Consistency After creating, the user should see the most recent list of meme reminders 
 (strong consistency supported by Cloud Datastore) Eventual Consistency Meme detail view might not have been generated and stored yet – 
 but you can always apologise to the user. Eventual consistency is often fine.
  106. 106. CONCLUSION
  107. 107. CONCLUSION Keep it simple (but not stupid!) Reduce the number of “things” you need to deal with – both from an architecture and a product perspective.
  108. 108. CONCLUSION Keep it simple (but not stupid!) Reduce the number of “things” you need to deal with – both from an architecture and a product perspective. Challenge existing “best practices” Have you been brainwashed by cargo cults in the past? The “best” practices always depend on the context and scope.
  109. 109. CONCLUSION Keep it simple (but not stupid!) Reduce the number of “things” you need to deal with – both from an architecture and a product perspective. Challenge existing “best practices” Have you been brainwashed by cargo cults in the past? The “best” practices always depend on the context and scope. Develop end-to-end Allows you to make better decisions for the entire system – and to iterate quickly for your MVP!

×