ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Bootstrapping Microservices
What is a Microservice?
Microservices are an organizational
scaling tool
Monoliths are great
RPC
Message Driven
Intro to microservices  GopherDay Taipei '17
G/RPC
Protobuf definition
package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
Go Implementation
// server is used to implement helloworld.GreeterServer.
type server struct{}
// SayHello implements helloworld.GreeterServer
func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
return &pb.HelloReply{Message: "Hello " + in.Name}, nil
}
Forget about config files
Environment variables
import "github.com/ianschenck/envflag"
bindAddress := envflag.String(
"ADDR",
":8080",
"Bind address for the api server")
Metrics
Metrics
import "github.com/prometheus/client_golang/prometheus"
var rpcDurations = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Name: "rpc_durations_seconds",
Help: "RPC latency distributions.",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
},
[]string{"service"}
func whatever() {
start := time.Now()
//do something
rpcDurations.Observe(time.Since(start))
}
Intro to microservices  GopherDay Taipei '17
Logging to files is obsolete
REK Stack
4 Rsyslog
4 Elastic Search
4 Kibana
Structured logging
{
"program": "microservice1", "host": "box01",
"log_level": "info", "msg": "Api Request recieved",
"user_id": "12345", "rpc_method": "post_add_tick"
}
Logging
import log "github.com/Sirupsen/logrus"
func main() {
log.SetFormatter(&log.JSONFormatter{})
//Will log to /dev/log
hook, err := logrus_syslog.NewSyslogHook("", "", syslog.LOG_INFO, "")
if err != nil {
log.Error("Unable to connect to local syslog daemon")
} else {
log.AddHook(hook)
}
}
Intro to microservices  GopherDay Taipei '17
Integration tests
Container based deploys
Docker file example
FROM golang:latest
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN go build -o main .
CMD ["/app/main"]
Docker build
docker build -t myapp:version .
Docker Run
docker run -V /dev/log:/dev/log -E=addr=:8080 myapp:version
Breakdown
4 Syslog -> -V /dev/log:/devlog
4 ENV Vars -> -E addr=:8080
4 Application container -> myapp:version
Continous Integration
Intro to microservices  GopherDay Taipei '17
Ansible + Docker
Kubernetes
Why is Go the future of microservices?
Questions?

More Related Content

Intro to microservices GopherDay Taipei '17