DEPLOYING GO FUNCTIONS

Julien Bisconti

SRE / Data Engineer

Google Cloud Platform icon

contact

g.dev/julien

slides: bisconti.cloud

Why deploying Go functions ?

Mental limitations


  • # decisions / day
  • # things to remember
  • speed of memory / reflexes

Demo

openfaas logo

docker swarm init
git clone https://github.com/openfaas/faas
cd faas
./deploy_stack.sh
open http://127.0.0.1:8080

How does it work

  • OpenFaas API Gateway routes into functions
  • Runs inside a container
  • Uses a watchdog process (web server)
  • Process STDIN and returns to STDOUT
  • Collects metrics in Prometheus

templates


import (
    "fmt"
    "io/ioutil"
    "log"
    "os"
    "handler/function"
)
func main() {
    input, err := ioutil.ReadAll(os.Stdin)
    if err != nil {
        log.Fatalf("Unable to read standard input: %s", err.Error())
    }
    fmt.Println(function.Handle(input))
}

See all templates

functions


// Handle a serverless request
func Handle(req []byte) string {
  return fmt.Sprintf("Hello, Go. You said: %s", string(req))
}

face detection handler

dockerfile

# Populate example here - i.e. "cat", "sha512sum" or "node index.js"
ENV fprocess="./handler"
# Set to true to see request in function logs
ENV write_debug="false"
EXPOSE 8080
HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1
CMD [ "fwatchdog" ]

Why deploying Go functions ?

Simplicity is complicated

Rob Pike

The Art of UNIX programming

dotGo 2015 - Rob Pike - Simplicity is Complicated

Mindset

connect services

Patrick Debois - From serverless to Service Full

Name a service for :

  • mails
  • chat
  • pictures
  • files
  • code
  • dns
  • payment

Why deploying Go functions ?

" we should build our own X "

where "X" is anything not related to the business

Example: framework, in-memory database, queue system, new programming language, etc.

We could build it

BUT

spending time on the business

makes more sense financially

  • Logging
  • Tracing
  • Metrics
  • Service identity and Auth
  • Circuit breaking
  • Traffic flow and policies
  • Failover
  • A/B testing
  • Fault injection
  • ...


➡️ ️ use code?

drawbacks

  • combination language/framework/version/feature
  • maintain, upgrade, migrate, retire
  • code pollution and complexity (+ testing)
  • deployment / rolling update
  • language/framework/version lock-in
  • debugging


➡️ ️ move it to the infrastructure

no code repository
mapping

Simon Wardly - Mapping

CODE

👇

INFRA

👇

SERVICE

THANK YOU

and I'm sorry 🙏
If you had to maintain my code
I hope you learned more by maintaining it
than me by writing it

contact

https://bisconti.cloud/

@julienBisconti

Slides made with Reveal.js and hugo-reveal