GO FROM PHP ENGINEER’S PERSPECTIVE
SOBIT AKHMEDOV
GO FROM PHP ENGINEER’S PERSPECTIVE
PHP FRAMEWORKS
▸ Symfony
▸ Laravel
▸ Zend Framework
GO FROM PHP ENGINEER’S PERSPECTIVE
PHP TOOLS AND COMMUNITY
▸ Composer
▸ Monolog
▸ PHP-FIG
GO FROM PHP ENGINEER’S PERSPECTIVE
THEY STARTED WITH PHP
▸ Yahoo!
▸ Wikipedia
▸ Wordpress
▸ Tumblr
GO FROM PHP ENGINEER’S PERSPECTIVE
PHP AND MICROSERVICES
▸ Good response time on single application only ✓
▸ Good for WEB development ✓
▸ Bad for microservices architectures: ✗
▸ Timeout handling ✗
▸ Metrics collection ✗
▸ Bulkheads ✗
▸ Circuit breakers ✗
MEET GO
GO (OFTEN REFERRED TO AS GOLANG) IS AN OPEN SOURCE PROGRAMMING LANGUAGE DEVELOPED AT GOOGLE IN 2007 BY ROBERT GRIESEMER, ROB PIKE, AND KEN THOMPSON. DESIGNED PRIMARILY FOR SYSTEMS PROGRAMMING, IT IS A COMPILED, STATICALLY TYPED LANGUAGE IN THE TRADITION OF C AND C++, WITH GARBAGE COLLECTION, VARIOUS SAFETY FEATURES AND CSP-STYLE CONCURRENT PROGRAMMING FEATURES ADDED.
Wikipedia
GO FROM PHP ENGINEER’S PERSPECTIVE
GO FROM PHP ENGINEER’S PERSPECTIVE
MEET GO
▸ Developed at Google in 2007
▸ Due to the frustration of dealing with the complexity
▸ Announced in November 2009
▸ Special feature: extreme simplicity
▸ Go: 25 keywords
▸ PHP: 67 keywords
GO FROM PHP ENGINEER’S PERSPECTIVE
BUILT WITH GO
▸ Docker
▸ Kubernetes
▸ etcd
▸ InfluxDb
GO FROM PHP ENGINEER’S PERSPECTIVE
GO AND MICROSERVICES▸ Fast compilation
▸ Parallel execution
▸ Transport protocols
▸ JSON over HTTP, gRPC, Protocol Buffers, Thrift
▸ Request tracing in Zipkin
▸ Metrics exporting to statsd, Prometheus, etc.
▸ Rate limiters
▸ … others
MORE ABOUT GO
GO FROM PHP ENGINEER’S PERSPECTIVE
LANGUAGE
▸ Strictly typed
▸ Type inference
GO FROM PHP ENGINEER’S PERSPECTIVE
LANGUAGE
▸ Multiple return types
GO FROM PHP ENGINEER’S PERSPECTIVE
LANGUAGE
▸ Multiple return types
GO FROM PHP ENGINEER’S PERSPECTIVE
LANGUAGE
▸ No foreach, no while, no do-while
GO FROM PHP ENGINEER’S PERSPECTIVE
LANGUAGE
▸ No foreach, no while, no do-while
GO FROM PHP ENGINEER’S PERSPECTIVE
LANGUAGE
▸ No foreach, no while, no do-while
GO FROM PHP ENGINEER’S PERSPECTIVE
LANGUAGE
▸ No foreach, no while, no do-while
GO FROM PHP ENGINEER’S PERSPECTIVE
LANGUAGE
▸ No classes, only structs
GO FROM PHP ENGINEER’S PERSPECTIVE
LANGUAGE
▸ No classes, only structs
GO FROM PHP ENGINEER’S PERSPECTIVE
LANGUAGE
▸ Goroutine — a function executing concurrently with other goroutines in the same address space
▸ Exits silently on completion
GO FROM PHP ENGINEER’S PERSPECTIVE
LANGUAGE
▸ Goroutine are “fire-and-forget”
▸ Channels - if we need the result
GO FROM PHP ENGINEER’S PERSPECTIVE
TOOLS
▸ go fmt
▸ go doc
▸ go vet
▸ go test
▸ go get github.com/hoisie/redis
▸ … others
GO FROM PHP ENGINEER’S PERSPECTIVE
DEPLOYING PHP APPLICATION (BASIC)
▸ Checkout the latest code on the target server into a new release folder
▸ Copy cached dependencies and install updated ones
▸ Copy environment-specific configuration files
▸ Run all the scripts to warm the application up
▸ Point the current release symlink into the new release folder
▸ Restart PHP-FPM
GO FROM PHP ENGINEER’S PERSPECTIVE
DEPLOYING PHP APPLICATION (ADVANCED)
▸ Checkout the latest code on the build server
▸ “Build” it (install dependencies, warm the caches up, etc.)
▸ Create a distributable “artifact” (an archived tar.gz file)
▸ Transfer the artifact to the target server
▸ Unarchive into a new release folder
▸ Point the current release symlink into the new release folder
▸ Restart PHP-FPM
GO FROM PHP ENGINEER’S PERSPECTIVE
DEPLOYING GO APPLICATION
▸ Checkout the latest code on the build server
▸ Build it (note the absence of quotes)
▸ Transfer the artifact (again no quotes) to the target server
▸ Restart the running application
GO FROM PHP ENGINEER’S PERSPECTIVE
DEPLOYING GO APPLICATION
▸ No need to install Go on target servers
▸ Builds for different OS and architectures
▸ From single machine
▸ Even for Windows!
CONCLUSION
GO FROM PHP ENGINEER’S PERSPECTIVE
CONCLUSION
▸ Premature decomposition = failure
▸ PHP fits monolithic application strategy
▸ Building microservices with PHP is painful
▸ Consider Go
▸ Easier than Java or Scala
▸ Performance is not far behind C
GO FROM PHP ENGINEER’S PERSPECTIVE
HOW CAN I CONTINUE?▸ Learn: https://golang.org/doc/#learning
▸ Learn more: https://github.com/golang/go/wiki/Learn
▸ IDEs: https://github.com/golang/go/wiki/IDEsAndTextEditorPlugins
▸ https://github.com/go-lang-plugin-org/go-lang-idea-plugin
▸ Go kit: https://github.com/go-kit/kit
▸ Client-side Go: http://www.gopherjs.org/
▸ Go for mobile apps: https://github.com/golang/go/wiki/Mobile
QUESTIONS?
GO FROM PHP ENGINEER’S PERSPECTIVE
THANKS!
Sobit Akhmedov