SlideShare uma empresa Scribd logo
1 de 48
Hurry Up and Go
(But Not Too Fast)
Stuart Fettinger
sfettinger@nvisia.com
About Me
Project Architect at NVISIA
10+ years of experience designing, developing, and delivering solutions
Recent co-founder of a tech startup
Passionate about limiting tech debt through clean and efficient design
Topic Breakdown
Brief Introduction to GO
Guiding Principles and Core Concepts
Go’s strong (and not so strong) suits
Highlighting when GO is a preferred choice, and when it’s not,
through real-world examples
Designing a GO Microservice
Tips for your design to take advantage of Go to its fullest and avoid
common pitfalls
What is GoLang?
• Developed by Google in 2007
• Designed to overcome criticism
of other languages
•Statically typed and compiled
• Syntactically similar to C
Go’s Guiding
Principles
Simplicity
Type inference
Declare-and-initialize operations
No generics
Composition rather than inheritance
Readability
As little “magic” as possible
Explicit and lean error mechanisms
Orthogonality
Do one thing well, keep things simple, standardize communication
Elimination of cross-linking complexity
Performance
Built in garbage collection
Synchronization, channels and Go routines
Pointers
A Basic Example
Main package – compiled binary
Short, concise imports
Function keywords
Multiple return values
Meaningful spaces – no semicolons
Core Concepts
Packages provide logical groupings and reusable functionality
Every Go program starts in the main package’s main() function
Main package is compiled to binary
Functions beginning with a capital letter are exported outside their package
Functions beginning with a lowercase letter are essentially private
Packages
Functions are stand-alone pieces of functionality
Methods are functions with receivers - tied to a type
Methods should be used when state is important and with interfaces
Rule of thumb – prefer methods over functions
Methods vs. Functions
Variables that store the memory address of other variables
Zero type of nil – popularly used where nil is valid and relied upon
Memory address available via &
Pointer dereferenced via *
Pointers
Structs
Named collections of fields
When initialized, all fields are set to their zero values
Fields of a struct are accessed via “.” operator
Composition over inheritance – one struct cannot be the child of another
Structs can contain other structs
Named collections of method signatures
No “Implements” keyword – can be implemented directly by implementing all methods
Interfaces can be empty – automatically satisfied by any type
Go’s answer to polymorphism
Interfaces
Errors
Errors are treated as values
Stack traces don’t come for free with errors
Idiomatic to check for errors frequently via “if” operations
No try/catch framework – error handling up to developers
Go Routines
Lightweight threads managed by the Go runtime
Spawned by simply using “go” keyword
Initially small stack size with ability to scale
Leverage channels to pass messages, block, and sync between Go routines
Performant – can run thousands of Go routines at a time with little drag
What Go Doesn’t Have
• Inheritance
• Classes
• Exceptions
• Generics
Deciding When to
Use Go
Go Is Not One-Size Fits All
• Go works well in some cases, not so great in others
• Some scenarios to consider Go
• Small, predictable routines
• Where performance margins are razor thin (ie: trading)
• Quick start-up with limited resources
• Scaling is a prime factor or an unknown
• Concurrency and communication is a prime use-case
• Scenarios where Go may fall short
• Where complexity requires extensive third-party libraries
• Where OO reduces complexity
• Front-end MVC
• Team makeup is less experienced
• Remember – design decisions should be case-by-case – try not to promote blanket use of technology
Considerations
• What are the requirements for the problem I am trying to solve?
• Can I solve the problem another way, and will doing so lose me any benefits?
• Consider technical pros and cons, but also intangible factors
• Developer happiness
• Community support
• Framework maturity
• Current trends
• Consider supporting a solution after it is live
• Scaling needs
• Technical debt and BAU maintenance
Use Case #1
Requirements
• Microservice with capabilities to
• Store high resolution images on the cloud
• Resize images without damaging resolution
• Be available on-demand to fetch data
• Data throughput may be larger than other streams (ie: text)
As a user, I want to be able to upload a high-resolution image, and retrieve it later in
whatever dimensions I want, so that I can use the image for different situations
Use Case #1
Performance exceeds
that of an interpreted
language
Package manager and
libraries are more
diverse
Higher scalability to
meet unknown data
demands
Ease of using docker to
spin up containers
Serverless architecture
support
Further developed
community
Smaller learning curve
for front-end
developers
Channels and
GoRoutines to spread
out workloads
Use Case #2
Requirements
• Several microservices connecting with different resources and providing different outputs
• Similarities in data may be a high percentage of make-up
• Data has potential to be large – multi-threading may be important
As a user, I want to be able to call APIs for different but similar data, and aggregate them
together, so that I can streamline my usage of that data
Use Case #2
Lightweight syntax –
avoid getting lost in
complex data
manipulation
Inheritance and
genericsHigh Performance
Mature libraries for
persistence and data
combination
Go Channels and Go
Routines – automate
polling data
Extensive API strategy
support
Use Case #3
Requirements
• Many file types may exist in many different formats
• Files may be made available at different times
• Must store data, potentially in a variety of formats
As a user, I want to be able to ingest and persist files from many different sources, so that I
can scrape the data later via my own processes
Use Case #3
Significant performance
benefits
Mature ORM libraries
Low learning curve
Wide database support
Higher developer
popularity
Multithreading
capabilities
Use Case #4
Requirements
• Application available on the web, potentially mobile as well
• Rich Interface and modern design
• Communicates with various microservices
• Possibilities are endless – login, registration, alerts, etc…
As a developer, I want to create a front-end web application for my users to interact with,
so that I can expand my customer base
Use Case #4
Lower learning curve Mature MVVM patterns
and support
Templating and
rendering engines
High number of built-in
must-haves for front-
end development
Third-party routing
support
Seamless integration
with a back-end Go
stack (Revel)
Designing a GO
Microservice - Tips
Don’t Reinvent
the Wheel#1
Plenty of third-party
frameworks exist to
ease microservice
development
GoMicro
• Foundation for RPC and event-driven communication with reasonable defaults built in
• Out-of-the-box:
• Service discovery
• Auto registration and name resolution
• Load Balancing
• Even distribution and node-retry
• Message Encoding
• Proto-RPC and Json-RPC by default
• Asynchronous
• Event-driven architecture
• “Pluggable” interfaces
• Platform agnostic implementations
GoKit
• Toolkit for Go – designed to be imported into a binary package
• Fills the gaps left by the base package(s)
• Security
• Monitoring
• Service Discovery
• Can be thought of as similar to
• Spring Boot
• Eureka
• Ribbon
• Integrates well with Docker, Kubernetes, and Heroku
• Different from GoMicro in that it’s more of a toolkit, less of a platform
Leverage
Interfaces#2
Interfaces provide
portable, independent
implementation
opportunities
• Expose interfaces as contracts between services
• Centralize common features such as logging and queueing
• Allow platform-agnostic implementations
• ie: data layer interfaces and repositories
ORM is Your
Friend#3
Make your entities
more meaningful by
tying them to an ORM
implementation
Go’s lean syntax drives you to use straight SQL prepared statements
• Gets messy fast with many parameters and outputs
• Nil considerations are difficult – Go values not easily nillable
• Compiler will not catch issues with prepared statements, field names, etc...
GoRM
• Provides associations between entities – Has One, Has Many, Many to
Many, Belongs To, etc…
• Uses any field with ID as the primary key – no need to annotate
• Auto support for creation, update, and soft-delete timestamps
• Auto-update capabilities – No need to explicitly call update vs insert
• Provides hooks to execute functionality pre or post running SQL
• API for transaction management and rollback
• Eager loading vs lazy loading (default) capabilities
• Can run raw SQL if needed
Centralize
configurations#4
Go’s binary nature may drive you to place configs in files within the application, or
on the server in a central location
• It works – but you’re missing out
Create a central location where configurations live – ideally another microservice
serving up files
• Place security on top of configs
• Integrate with CI/CD pipelines
• Inject configs via use of Docker secrets, etc…
• Leverage caching for failure scenarios
Read configurations into your services by leveraging Go-based configuration
solutions
Viper
• API to find and load config files of varying formats
• Also supports writing configuration files
• Provides defaults and gracefully handles overrides
• Live-watching of configs, and hot-reloading
• Alias-based naming, allowing non-breaking renames
• Uses environment variables to manage different configurations
• Remote key/value store support
Centralized
configuration keeps
things DRY
Make Errors
Meaningful#5
• Errors are values so it’s easy to treat them as strings and just pass them up the
chain
• There is no stacktrace included with an error by default
• There is no concept of an exception in Go – up to the developer to handle
• Implement the error interface to construct meaningful errors of different types
• Add stack trace information by using go-errors package
• Add important logging info using go log flags
Supplement your error
framework with
additional logging and
packages
When Designing Your Microservices…
• Understand the cases where your chosen technology works best
• Do POCs, reach out to the community, benchmark test – make informed decisions based on use cases
• Don’t be afraid to mix and match to get your desired result
• i.e – Go, third-party Go packages, Spring, Docker, etc…
• Always look for opportunities to improve, but not to the point of development paralysis
• Go is meant to be simple – don’t head down the rabbit hole of over-inventiveness
• Don’t invite unnecessary technical debt
• Consider your long-term goals and scaling needs when deciding how to implement functionality
• Design for technical soundness but also developer satisfaction
• Go is so popular, in part, because it’s fun
Questions

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Go Programming language, golang
Go Programming language, golangGo Programming language, golang
Go Programming language, golang
 
Golang
GolangGolang
Golang
 
Go Programming Language (Golang)
Go Programming Language (Golang)Go Programming Language (Golang)
Go Programming Language (Golang)
 
GoLang Introduction
GoLang IntroductionGoLang Introduction
GoLang Introduction
 
Go lang
Go langGo lang
Go lang
 
Go Programming Language by Google
Go Programming Language by GoogleGo Programming Language by Google
Go Programming Language by Google
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) Language
 
Concurrency With Go
Concurrency With GoConcurrency With Go
Concurrency With Go
 
GO programming language
GO programming languageGO programming language
GO programming language
 
Golang (Go Programming Language)
Golang (Go Programming Language)Golang (Go Programming Language)
Golang (Go Programming Language)
 
Introduction to Go programming language
Introduction to Go programming languageIntroduction to Go programming language
Introduction to Go programming language
 
Goroutines and Channels in practice
Goroutines and Channels in practiceGoroutines and Channels in practice
Goroutines and Channels in practice
 
Golang 101
Golang 101Golang 101
Golang 101
 
Introduction to Go language
Introduction to Go languageIntroduction to Go language
Introduction to Go language
 
Golang getting started
Golang getting startedGolang getting started
Golang getting started
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
 
Go Language presentation
Go Language presentationGo Language presentation
Go Language presentation
 
Go Lang Tutorial
Go Lang TutorialGo Lang Tutorial
Go Lang Tutorial
 
Concurrency in Golang
Concurrency in GolangConcurrency in Golang
Concurrency in Golang
 

Semelhante a Introduction to GoLang

Model-driven and low-code development for event-based systems | Bobby Calderw...
Model-driven and low-code development for event-based systems | Bobby Calderw...Model-driven and low-code development for event-based systems | Bobby Calderw...
Model-driven and low-code development for event-based systems | Bobby Calderw...
HostedbyConfluent
 
Community day 2013 applied architectures
Community day 2013   applied architecturesCommunity day 2013   applied architectures
Community day 2013 applied architectures
Panagiotis Kefalidis
 
How to Migrate from .NET to Drupal
How to Migrate from .NET to DrupalHow to Migrate from .NET to Drupal
How to Migrate from .NET to Drupal
Acquia
 
Web development tips and tricks
Web development tips and tricksWeb development tips and tricks
Web development tips and tricks
maxo_64
 
How to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle coreHow to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle core
Dan Poltawski
 

Semelhante a Introduction to GoLang (20)

Model-driven and low-code development for event-based systems | Bobby Calderw...
Model-driven and low-code development for event-based systems | Bobby Calderw...Model-driven and low-code development for event-based systems | Bobby Calderw...
Model-driven and low-code development for event-based systems | Bobby Calderw...
 
20160422 Speedy Framework Enterprise Application Development Platform
20160422 Speedy Framework Enterprise Application Development Platform20160422 Speedy Framework Enterprise Application Development Platform
20160422 Speedy Framework Enterprise Application Development Platform
 
gRPC, GraphQL, REST - Which API Tech to use - API Conference Berlin oct 20
gRPC, GraphQL, REST - Which API Tech to use - API Conference Berlin oct 20gRPC, GraphQL, REST - Which API Tech to use - API Conference Berlin oct 20
gRPC, GraphQL, REST - Which API Tech to use - API Conference Berlin oct 20
 
Comparing Legacy and Modern e-commerce solutions
Comparing Legacy and Modern e-commerce solutionsComparing Legacy and Modern e-commerce solutions
Comparing Legacy and Modern e-commerce solutions
 
Manatee to Dolphin: Transitioning to a Startup Mentality
Manatee to Dolphin: Transitioning to a Startup MentalityManatee to Dolphin: Transitioning to a Startup Mentality
Manatee to Dolphin: Transitioning to a Startup Mentality
 
Making software development processes to work for you
Making software development processes to work for youMaking software development processes to work for you
Making software development processes to work for you
 
Community day 2013 applied architectures
Community day 2013   applied architecturesCommunity day 2013   applied architectures
Community day 2013 applied architectures
 
How to Migrate from .NET to Drupal
How to Migrate from .NET to DrupalHow to Migrate from .NET to Drupal
How to Migrate from .NET to Drupal
 
resume4
resume4resume4
resume4
 
Designing and Implementing Information Systems with Event Modeling, Bobby Cal...
Designing and Implementing Information Systems with Event Modeling, Bobby Cal...Designing and Implementing Information Systems with Event Modeling, Bobby Cal...
Designing and Implementing Information Systems with Event Modeling, Bobby Cal...
 
Web frameworks
Web frameworksWeb frameworks
Web frameworks
 
Agile Software Development
Agile Software DevelopmentAgile Software Development
Agile Software Development
 
Meetup. Technologies Intro for Non-Tech People
Meetup. Technologies Intro for Non-Tech PeopleMeetup. Technologies Intro for Non-Tech People
Meetup. Technologies Intro for Non-Tech People
 
Software Design
Software DesignSoftware Design
Software Design
 
Building Information Systems using Event Modeling (Bobby Calderwood, Evident ...
Building Information Systems using Event Modeling (Bobby Calderwood, Evident ...Building Information Systems using Event Modeling (Bobby Calderwood, Evident ...
Building Information Systems using Event Modeling (Bobby Calderwood, Evident ...
 
Web development tips and tricks
Web development tips and tricksWeb development tips and tricks
Web development tips and tricks
 
How to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle coreHow to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle core
 
After the LAMP, it's time to get MEAN
After the LAMP, it's time to get MEANAfter the LAMP, it's time to get MEAN
After the LAMP, it's time to get MEAN
 
Django è pronto per l'Enterprise
Django è pronto per l'EnterpriseDjango è pronto per l'Enterprise
Django è pronto per l'Enterprise
 
Prominent Back-end frameworks to consider in 2022!
Prominent Back-end frameworks to consider in 2022!Prominent Back-end frameworks to consider in 2022!
Prominent Back-end frameworks to consider in 2022!
 

Mais de NVISIA

Mais de NVISIA (16)

The Evolution of Architecture
The Evolution of ArchitectureThe Evolution of Architecture
The Evolution of Architecture
 
Expected Result - A UX Story
Expected Result - A UX StoryExpected Result - A UX Story
Expected Result - A UX Story
 
Antifragile Teams
Antifragile TeamsAntifragile Teams
Antifragile Teams
 
Digital Operations Service Design
Digital Operations Service DesignDigital Operations Service Design
Digital Operations Service Design
 
Executive Briefing: The Why, What, and Where of Containers
Executive Briefing: The Why, What, and Where of ContainersExecutive Briefing: The Why, What, and Where of Containers
Executive Briefing: The Why, What, and Where of Containers
 
Strengthening Business/IT Relationships
Strengthening Business/IT RelationshipsStrengthening Business/IT Relationships
Strengthening Business/IT Relationships
 
Achieving Business Alignment
Achieving Business AlignmentAchieving Business Alignment
Achieving Business Alignment
 
Intro to AWS Machine Learning
Intro to AWS Machine LearningIntro to AWS Machine Learning
Intro to AWS Machine Learning
 
2015 DevOps Breakfast - DevOps in Action
2015 DevOps Breakfast - DevOps in Action2015 DevOps Breakfast - DevOps in Action
2015 DevOps Breakfast - DevOps in Action
 
DAMA Chicago - Ensuring your data lake doesn’t become a data swamp
DAMA Chicago - Ensuring your data lake doesn’t become a data swampDAMA Chicago - Ensuring your data lake doesn’t become a data swamp
DAMA Chicago - Ensuring your data lake doesn’t become a data swamp
 
Scaling the Lean Startup in the Enterprise
Scaling the Lean Startup in the EnterpriseScaling the Lean Startup in the Enterprise
Scaling the Lean Startup in the Enterprise
 
INNOVATION BLUEPRINTS FOR BIMODAL IT
INNOVATION BLUEPRINTS FOR BIMODAL ITINNOVATION BLUEPRINTS FOR BIMODAL IT
INNOVATION BLUEPRINTS FOR BIMODAL IT
 
Building a Data Talent Pipeline in Southeaster Wisconsin
Building a Data Talent Pipeline in Southeaster WisconsinBuilding a Data Talent Pipeline in Southeaster Wisconsin
Building a Data Talent Pipeline in Southeaster Wisconsin
 
12/2/2014 Milwaukee Agile Presentation: Persuading Your Oganization to be Agile
12/2/2014 Milwaukee Agile Presentation: Persuading Your Oganization to be Agile12/2/2014 Milwaukee Agile Presentation: Persuading Your Oganization to be Agile
12/2/2014 Milwaukee Agile Presentation: Persuading Your Oganization to be Agile
 
Big Data 2.0 - Milwaukee Big Data User Group Presentation
Big Data 2.0 - Milwaukee Big Data User Group Presentation Big Data 2.0 - Milwaukee Big Data User Group Presentation
Big Data 2.0 - Milwaukee Big Data User Group Presentation
 
NVISIA Mobile Trends Presentation
NVISIA Mobile Trends PresentationNVISIA Mobile Trends Presentation
NVISIA Mobile Trends Presentation
 

Último

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Último (20)

%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 

Introduction to GoLang

  • 1. Hurry Up and Go (But Not Too Fast) Stuart Fettinger sfettinger@nvisia.com
  • 2. About Me Project Architect at NVISIA 10+ years of experience designing, developing, and delivering solutions Recent co-founder of a tech startup Passionate about limiting tech debt through clean and efficient design
  • 3. Topic Breakdown Brief Introduction to GO Guiding Principles and Core Concepts Go’s strong (and not so strong) suits Highlighting when GO is a preferred choice, and when it’s not, through real-world examples Designing a GO Microservice Tips for your design to take advantage of Go to its fullest and avoid common pitfalls
  • 5. • Developed by Google in 2007 • Designed to overcome criticism of other languages •Statically typed and compiled • Syntactically similar to C
  • 6. Go’s Guiding Principles Simplicity Type inference Declare-and-initialize operations No generics Composition rather than inheritance Readability As little “magic” as possible Explicit and lean error mechanisms Orthogonality Do one thing well, keep things simple, standardize communication Elimination of cross-linking complexity Performance Built in garbage collection Synchronization, channels and Go routines Pointers
  • 7. A Basic Example Main package – compiled binary Short, concise imports Function keywords Multiple return values Meaningful spaces – no semicolons
  • 9. Packages provide logical groupings and reusable functionality Every Go program starts in the main package’s main() function Main package is compiled to binary Functions beginning with a capital letter are exported outside their package Functions beginning with a lowercase letter are essentially private Packages
  • 10.
  • 11. Functions are stand-alone pieces of functionality Methods are functions with receivers - tied to a type Methods should be used when state is important and with interfaces Rule of thumb – prefer methods over functions Methods vs. Functions
  • 12.
  • 13. Variables that store the memory address of other variables Zero type of nil – popularly used where nil is valid and relied upon Memory address available via & Pointer dereferenced via * Pointers
  • 14.
  • 15.
  • 16. Structs Named collections of fields When initialized, all fields are set to their zero values Fields of a struct are accessed via “.” operator Composition over inheritance – one struct cannot be the child of another Structs can contain other structs
  • 17.
  • 18. Named collections of method signatures No “Implements” keyword – can be implemented directly by implementing all methods Interfaces can be empty – automatically satisfied by any type Go’s answer to polymorphism Interfaces
  • 19.
  • 20. Errors Errors are treated as values Stack traces don’t come for free with errors Idiomatic to check for errors frequently via “if” operations No try/catch framework – error handling up to developers
  • 21.
  • 22. Go Routines Lightweight threads managed by the Go runtime Spawned by simply using “go” keyword Initially small stack size with ability to scale Leverage channels to pass messages, block, and sync between Go routines Performant – can run thousands of Go routines at a time with little drag
  • 23.
  • 24. What Go Doesn’t Have • Inheritance • Classes • Exceptions • Generics
  • 26. Go Is Not One-Size Fits All • Go works well in some cases, not so great in others • Some scenarios to consider Go • Small, predictable routines • Where performance margins are razor thin (ie: trading) • Quick start-up with limited resources • Scaling is a prime factor or an unknown • Concurrency and communication is a prime use-case • Scenarios where Go may fall short • Where complexity requires extensive third-party libraries • Where OO reduces complexity • Front-end MVC • Team makeup is less experienced • Remember – design decisions should be case-by-case – try not to promote blanket use of technology
  • 27. Considerations • What are the requirements for the problem I am trying to solve? • Can I solve the problem another way, and will doing so lose me any benefits? • Consider technical pros and cons, but also intangible factors • Developer happiness • Community support • Framework maturity • Current trends • Consider supporting a solution after it is live • Scaling needs • Technical debt and BAU maintenance
  • 28. Use Case #1 Requirements • Microservice with capabilities to • Store high resolution images on the cloud • Resize images without damaging resolution • Be available on-demand to fetch data • Data throughput may be larger than other streams (ie: text) As a user, I want to be able to upload a high-resolution image, and retrieve it later in whatever dimensions I want, so that I can use the image for different situations
  • 29. Use Case #1 Performance exceeds that of an interpreted language Package manager and libraries are more diverse Higher scalability to meet unknown data demands Ease of using docker to spin up containers Serverless architecture support Further developed community Smaller learning curve for front-end developers Channels and GoRoutines to spread out workloads
  • 30. Use Case #2 Requirements • Several microservices connecting with different resources and providing different outputs • Similarities in data may be a high percentage of make-up • Data has potential to be large – multi-threading may be important As a user, I want to be able to call APIs for different but similar data, and aggregate them together, so that I can streamline my usage of that data
  • 31. Use Case #2 Lightweight syntax – avoid getting lost in complex data manipulation Inheritance and genericsHigh Performance Mature libraries for persistence and data combination Go Channels and Go Routines – automate polling data Extensive API strategy support
  • 32. Use Case #3 Requirements • Many file types may exist in many different formats • Files may be made available at different times • Must store data, potentially in a variety of formats As a user, I want to be able to ingest and persist files from many different sources, so that I can scrape the data later via my own processes
  • 33. Use Case #3 Significant performance benefits Mature ORM libraries Low learning curve Wide database support Higher developer popularity Multithreading capabilities
  • 34. Use Case #4 Requirements • Application available on the web, potentially mobile as well • Rich Interface and modern design • Communicates with various microservices • Possibilities are endless – login, registration, alerts, etc… As a developer, I want to create a front-end web application for my users to interact with, so that I can expand my customer base
  • 35. Use Case #4 Lower learning curve Mature MVVM patterns and support Templating and rendering engines High number of built-in must-haves for front- end development Third-party routing support Seamless integration with a back-end Go stack (Revel)
  • 38. Plenty of third-party frameworks exist to ease microservice development GoMicro • Foundation for RPC and event-driven communication with reasonable defaults built in • Out-of-the-box: • Service discovery • Auto registration and name resolution • Load Balancing • Even distribution and node-retry • Message Encoding • Proto-RPC and Json-RPC by default • Asynchronous • Event-driven architecture • “Pluggable” interfaces • Platform agnostic implementations GoKit • Toolkit for Go – designed to be imported into a binary package • Fills the gaps left by the base package(s) • Security • Monitoring • Service Discovery • Can be thought of as similar to • Spring Boot • Eureka • Ribbon • Integrates well with Docker, Kubernetes, and Heroku • Different from GoMicro in that it’s more of a toolkit, less of a platform
  • 40. Interfaces provide portable, independent implementation opportunities • Expose interfaces as contracts between services • Centralize common features such as logging and queueing • Allow platform-agnostic implementations • ie: data layer interfaces and repositories
  • 42. Make your entities more meaningful by tying them to an ORM implementation Go’s lean syntax drives you to use straight SQL prepared statements • Gets messy fast with many parameters and outputs • Nil considerations are difficult – Go values not easily nillable • Compiler will not catch issues with prepared statements, field names, etc... GoRM • Provides associations between entities – Has One, Has Many, Many to Many, Belongs To, etc… • Uses any field with ID as the primary key – no need to annotate • Auto support for creation, update, and soft-delete timestamps • Auto-update capabilities – No need to explicitly call update vs insert • Provides hooks to execute functionality pre or post running SQL • API for transaction management and rollback • Eager loading vs lazy loading (default) capabilities • Can run raw SQL if needed
  • 44. Go’s binary nature may drive you to place configs in files within the application, or on the server in a central location • It works – but you’re missing out Create a central location where configurations live – ideally another microservice serving up files • Place security on top of configs • Integrate with CI/CD pipelines • Inject configs via use of Docker secrets, etc… • Leverage caching for failure scenarios Read configurations into your services by leveraging Go-based configuration solutions Viper • API to find and load config files of varying formats • Also supports writing configuration files • Provides defaults and gracefully handles overrides • Live-watching of configs, and hot-reloading • Alias-based naming, allowing non-breaking renames • Uses environment variables to manage different configurations • Remote key/value store support Centralized configuration keeps things DRY
  • 46. • Errors are values so it’s easy to treat them as strings and just pass them up the chain • There is no stacktrace included with an error by default • There is no concept of an exception in Go – up to the developer to handle • Implement the error interface to construct meaningful errors of different types • Add stack trace information by using go-errors package • Add important logging info using go log flags Supplement your error framework with additional logging and packages
  • 47. When Designing Your Microservices… • Understand the cases where your chosen technology works best • Do POCs, reach out to the community, benchmark test – make informed decisions based on use cases • Don’t be afraid to mix and match to get your desired result • i.e – Go, third-party Go packages, Spring, Docker, etc… • Always look for opportunities to improve, but not to the point of development paralysis • Go is meant to be simple – don’t head down the rabbit hole of over-inventiveness • Don’t invite unnecessary technical debt • Consider your long-term goals and scaling needs when deciding how to implement functionality • Design for technical soundness but also developer satisfaction • Go is so popular, in part, because it’s fun