<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Roger Chapman on Medium]]></title>
        <description><![CDATA[Stories by Roger Chapman on Medium]]></description>
        <link>https://medium.com/@rogchap?source=rss-94b2f66fc7cb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*KjGPQMyCj-rGH4Eczg3FGg.jpeg</url>
            <title>Stories by Roger Chapman on Medium</title>
            <link>https://medium.com/@rogchap?source=rss-94b2f66fc7cb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 11:47:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rogchap/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Flexible mocking for testing in Go]]></title>
            <link>https://medium.com/mitti-engineering/flexible-mocking-for-testing-in-go-f952869e34f5?source=rss-94b2f66fc7cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/f952869e34f5</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[interfaces]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Roger Chapman]]></dc:creator>
            <pubDate>Wed, 21 Jul 2021 02:12:10 GMT</pubDate>
            <atom:updated>2021-08-19T08:02:52.997Z</atom:updated>
            <content:encoded><![CDATA[<p>SafetyCulture’s codebase is made up of many micro-services, many of which are written in Go. These micro-services talk to other micro-services and may connect to one or more datastores.</p><figure><img alt="Go Gopher playing with an abicus" src="https://cdn-images-1.medium.com/max/924/1*yeJ6v1BDsdR77b8WMv2wGA.png" /><figcaption>Source: <a href="https://github.com/marcusolsson/gophers/blob/master/gopherdata-gopher.png">https://github.com/marcusolsson/gophers/blob/master/gopherdata-gopher.png</a></figcaption></figure><p><a href="https://en.wikipedia.org/wiki/Mock_object">Mocking</a> is an essential tool to help unit test our code paths without using a real [integration] client.</p><p>In Go (and other languages) it’s a very understood pattern to use interfaces to achieve mocking.</p><h3>TL;DR</h3><p>Packages should return concrete (usually pointer or struct) types: that way, new methods can be added to implementations without requiring extensive refactoring.</p><p>We still take advantage of Go’s implicit interfaces to aid in testing/mocking, and it can all be done without a testing/mocking framework.</p><p>Key takeaways:</p><ul><li>avoid large interfaces</li><li>only use the interfaces/methods that you need</li><li>use nil and empty structs to mock your happy path</li><li>customize your mocks with function properties</li></ul><h3>The Anti-Pattern</h3><p>Throughout our codebase it’s very common to see code like this:</p><pre>type Store interface {<br>    ListUsers() ([]*User, error)<br>    ListTeamsByUser(userID int) ([]*Team, error)<br>    ListAddressesByUser(userID int) (*[]Address, error)<br>    // ...etc</pre><pre>    GetUser(id int) (*User, error)<br>    GetTeam(id int) (*Team, error)<br>    // ...etc</pre><pre>    CreateUser(user *User) (int, error)<br>    CreateTeam(userID int, team *Team) (int, error)<br>    // ...etc</pre><pre>    SetUserDefaultAddress(userID int, addressID int) error<br>    // ...etc<br>}</pre><pre>type store struct {<br>    db sql.DB<br>}</pre><pre>func NewStore(conn string) Store {<br>    db := initDB(conn)<br>    return &amp;store{db:db}<br>}</pre><p>What we observe above is an interface with a large number of methods and a constructor that returns the Store interface.</p><p>But we <a href="https://github.com/golang/go/wiki/CodeReviewComments#interfaces">know that this is an anti-pattern</a> (<em>we’ll be addressing this later</em>):</p><blockquote>Do not define interfaces on the implementor side of an API “for mocking”; instead, design the API so that it can be tested using the public API of the real implementation.</blockquote><h3>The Good</h3><p>Ignoring that it’s an anti-pattern for now; at first glance, the above pattern appears to make sense and we can easily use our Store interface wherever we need to by passing the same interface:</p><pre>SomeHandler(ctx context.Context, store db.Store, userID int) error {<br>    user, err := store.GetUser(userID)<br>    if err != nil {<br>        return err<br>    }<br>    // ...<br>    team, err := store.GetTeam(user.DefaultTeam)<br>    if err != nil {<br>        return err<br>    }<br>    // ...<br>}</pre><pre>SomeOtherHandler(ctx context.Context, store db.Store, firstname, lastname string) error {<br>    user := User{Firstname: firstname, Lastname: lastname}<br>    if err := store.CreateUser(&amp;user); err != nil {<br>        return err<br>    }<br>    // ...<br>}</pre><h3>The Bad</h3><p>This “convenience” comes at a cost; the hidden problem is that in order to test the two functions above we need to mock the entire Store interface, even when we are only using a sub set of the functions (some <em>method bodies ignored for brevity</em>):</p><pre>type storeMock struct {<br>    getUser *User<br>    getUserErr error<br>    getTeam *Team<br>    getTeamErr error<br>    // ...<br>}</pre><pre>func (m *storeMock) ListUsers() ([]*User, error) {}<br>func (m *storeMock) ListTeamsByUser(userID int) ([]*Team, error) {}<br>func (m *storeMock) ListAddressesByUser(userID int) (*[]Address, error) {}</pre><pre>func (m *storeMock) GetUser(id int) (*User, error) {<br>    return m.getUser, m.getUserErr<br>}</pre><pre>func (m *storeMock) GetTeam(id int) (*Team, error) {<br>    return m.getTeam, m.getTeamErr<br>}</pre><pre>func (m *storeMock) CreateUser(user *User) (int, error) {}<br>func (m *storeMock) CreateTeam(userID int, team *Team) (int, error) {}<br>func (m *storeMock) SetUserDefaultAddress(userID int, addressID int) error {}</pre><p>Creating a mock for each method we want to test would be very painful, and hard to maintain, so we tend to use a single mock struct for all our tests.</p><p>Every time we add a new interface method we would need to update our mocks and maybe even have to update our tests.</p><h3>The Ugly</h3><p>Many of our teams turned to <a href="https://github.com/vektra/mockery">auto-generation of these mocks</a> that work in tandem with testing frameworks.</p><p>This solves the problem of maintaining our own test mocks, but can still lead to “hard to maintain” tests.</p><p>Lets step through an example to discover some of the problems that we may encounter:</p><pre>// handler.go<br>SomeHandler(ctx context.Context, store db.Store, userID int) error {<br>    user, err := store.GetUser(userID)<br>    if err != nil {<br>        return err<br>    }<br>    // ...<br>    team, err := store.GetTeam(user.DefaultTeam)<br>    if err != nil {<br>        return err<br>    }<br>    // ...<br>}</pre><pre>// handler_test.go<br>func TestSomeHandler(t *testing.T) {<br>    tests := [...]struct {<br>        name string<br>        store func() db.Store<br>        shouldErr bool<br>    }{<br>        {<br>            &quot;HappyPath&quot;,<br>            func() db.Store {<br>                mock := &amp;dbmock.Store{}<br>                mock.On(&quot;GetUser&quot;, mock.Anything).Return(&amp;db.User{}, nil)<br>                mock.On(&quot;GetTeam&quot;, mock.Anything).Return(&amp;db.Team{}, nil)<br>                return mock<br>            },<br>            false,<br>        },<br> }<br> for _, tt := range tests {<br>     tt := tt<br>     t.Run(tt.name, func(t *testing.T){<br>         err := SomeHandler(context.Background(), tt.store(), 0)<br>         if tt.shouldErr &amp;&amp; err == nil {<br>              t.Error(&quot;expected error but got &lt;nil&gt;&quot;)<br>         }<br>      })<br> }</pre><p>The above test is a typical example (simplified) of a test that uses mocking. In this example we are only testing the “Happy Path” that skips over the error paths, but we can add more test, and using a similar pattern, test all code paths by mocking the input/output of the mocks.</p><h4>Problem One</h4><p>We add a method to our interface:</p><pre>type Store interface {<br>    ListUsers() ([]*User, error)<br>    ListTeamsByUser(userID int) ([]*Team, error)<br>    <br>    // ...etc</pre><pre>    AddUserToTeam(teamID, userID int) error<br>}</pre><p>Running our tests will fail with an error similar to:</p><pre>FAIL: cannot use *dbmock.Store as db.Store; missing method AddUserToTeam(teamID, userID int) error</pre><p>If we have auto-generated our mocks this is a simple fix, we just need to re-generate, but if we created the mock manually, we would need to add this function.</p><h4>Problem Two</h4><p>We now need to add this method to the body of our SomeHandler :</p><pre>SomeHandler(ctx context.Context, store db.Store, userID int) error {<br>    user, err := store.GetUser(userID)<br>    // ...</pre><pre>    err := store.AddUserToTeam(ateamID, userID)<br>    if err != nil {<br>        return err<br>    }</pre><pre>    team, err := store.GetTeam(user.DefaultTeam)<br>    // ...<br>}</pre><p>Running our tests again we get something like this error:</p><pre>mock: I don&#39;t know what to return because the method call was unexpected.<br>Either do Mock.On(&quot;AddUserToTeam&quot;).Return(...) first, or remove the AddUserToTeam() call.<br>This method was unexpected</pre><p>We can’t remove the call, so I guess we’ll need to mock the method in our test. But here is the kicker: we’ll have to update ALL our tests where the code path reaches this function, and if you have lots of tests (which you should) this gets repetitive:</p><pre>{<br>    &quot;HappyPath&quot;,<br>    func() db.Store {<br>        mock := &amp;dbmock.Store{}<br>        mock.On(&quot;GetUser&quot;, mock.Anything).Return(&amp;db.User{}, nil)<br>        <br>        mock.On(&quot;AddUserToTeam&quot;, mock.Anything, mock.Anything).Return(nil)<br>        <br>        mock.On(&quot;GetTeam&quot;, mock.Anything).Return(&amp;db.Team{}, nil)<br>        return mock<br>    },<br>    false,<br>},</pre><h4>Problem Three</h4><p>What happens if we refactor our Store interface? Thanks to static typing and the compiler, refactoring in Go is normally simple (very contrived example, but you should get the point):</p><pre>type Store interface {<br>    // ...etc</pre><pre>    --- GetTeam(id int) (*Team, error)<br>    +++ GetSquad(id int) (*Team, error)</pre><pre>   // ...etc<br>}</pre><p>This results in a similar error as before:</p><pre>mock: I don&#39;t know what to return because the method call was unexpected.<br>Either do Mock.On(&quot;GetSquad&quot;).Return(...) first, or remove the GetSquad() call.<br>This method was unexpected</pre><p>Because this <a href="https://github.com/stretchr/testify#mock-package">mocking framework</a> is using strings we can’t capitalise on Go refactoring tools, but have to find/replace &quot;GetTeam&quot; with the new method signature.</p><h3>Real Implementation</h3><p>Lets start by removing our large Store interface and returning the real implementation of our store so that we can start “<a href="https://medium.com/@cep21/what-accept-interfaces-return-structs-means-in-go-2fe879e25ee8">accepting interfaces, return structs</a>” and move away from our anti-pattern:</p><pre>type Store struct {<br>    db sql.DB<br>}</pre><pre>func NewStore(conn string) *Store {<br>    db := initDB(conn)<br>    return &amp;store{db:db}<br>}</pre><p>We still need to use interfaces to aid in mocking; interfaces should describe the behavior of your functions or methods required, thus reducing the coupling between the behavior and the implementation of that behavior.</p><p>Loose coupling between your packages ultimately results in more maintainable and readable code.</p><p>So rather than creating a large interface we create small interfaces (1 or 2 methods) for only the functions we need and compose interfaces if we need more than 1.</p><pre>type UserGetter interface {<br>    GetUser(id int) (*db.User, error)<br>}</pre><pre>type TeamGetter interface {<br>    GetTeam(id int) (*db.Team, error)<br>}</pre><pre>type UserTeamGetter interface {<br>    UserGetter<br>    TeamGetter<br>}</pre><pre>type UserCreator interface {<br>    CreateUser(user *db.User) (int, error)<br>}</pre><pre>SomeHandler(ctx context.Context, store UserTeamGetter, userID int) error {<br>    user, err := store.GetUser(userID)<br>    if err != nil {<br>        return err<br>    }<br>    // ...<br>    team, err := store.GetTeam(user.DefaultTeam)<br>    if err != nil {<br>        return err<br>    }<br>    // ...<br>}</pre><pre>SomeOtherHandler(ctx context.Context, store UserCreator, firstname, lastname string) error {<br>    user := User{Firstname: firstname, Lastname: lastname}<br>    if err := store.CreateUser(&amp;user); err != nil {<br>        return err<br>    }<br>    // ...<br>}</pre><p>With the functions only using the interfaces they need make it easier to test and we don’t need to change the caller code that uses the real store implementation.</p><pre>store := db.NewStore(conn)<br>SomeHandler(ctx, store, userID)</pre><h3>Happy Path</h3><p>In many test cases we need to have a general happy path through our mocked functions, so to reduce repetitive code we can make the nil struct (or empty struct ie. &amp;myMock{}) as the mock for the happy path:</p><pre>type userTeamMock struct {}</pre><pre>func (*userTeamMock) GetUser(id int) (*db.User, error) {<br>    return &amp;db.User{Firstname: &quot;foo&quot;, Lastname: &quot;bar&quot;}, nil<br>}</pre><pre>func (*userTeamMock) GetTeam(id int) (*db.Team, error) {<br>    return &amp;db.Team{Name: &quot;foobar&quot;}, nil<br>}</pre><pre>func TestSomeHandler(t *testing.T) {<br>    tests := [...]struct {<br>        name string<br>        store *userTeamMock<br>        shouldErr bool<br>    }{<br>        {<br>            &quot;HappyPath&quot;,<br>            nil,<br>            false,<br>        },<br> }<br> for _, tt := range tests {<br>     tt := tt<br>     t.Run(tt.name, func(t *testing.T){<br>         err := SomeHandler(context.Background(), tt.store, 0)<br>         if tt.shouldErr &amp;&amp; err == nil {<br>              t.Error(&quot;expected error but got &lt;nil&gt;&quot;)<br>         }<br>      })<br> }</pre><h3>Mock Functions</h3><p>The reason for creating a mock is that we can test more code branches than just the happy path. We can customize our mock to return anything we want to mock using function properties.</p><pre>type userTeamMock struct {<br>    getUserFn func(id int) (*db.User, error)<br>    getTeamFn func(id int) (*db.Team, error)<br>}</pre><pre>func (m *userTeamMock) GetUser(id int) (*db.User, error) {<br>    if m != nil &amp;&amp; m.getUserFn != nil {<br>        return m.getUserFn(id)<br>    }</pre><pre>    return &amp;db.User{Firstname: &quot;foo&quot;, Lastname: &quot;bar&quot;}, nil<br>}</pre><pre>func (*userTeamMock) GetTeam(id int) (*db.Team, error) {<br>    if m != nil &amp;&amp; m.getTeamFn != nil {<br>        return m.getTeamFn(id)<br>    }</pre><pre>    return &amp;db.Team{Name: &quot;foobar&quot;}, nil<br>}</pre><p>Using my mock now becomes much simpler; my happy path will always work if the userTeamMock is nil or empty and I can override that whenever we need:</p><pre>{<br>    &quot;GetUserError&quot;,<br>    &amp;userTeamMock{<br>        getUserFn: func GetUser(id int) (*db.User, error) {<br>           return nil, errors.New(&quot;user error&quot;)<br>        }<br>    },<br>    true,<br>},<br>{<br>    &quot;GetTeamError&quot;,<br>    &amp;userTeamMock{<br>        getTeamFn: func GetTeam(id int) (*db.Team, error) {<br>           return nil, errors.New(&quot;team error&quot;)<br>        }<br>    },<br>    true,<br>},<br>{<br>    &quot;HappyPath&quot;,<br>    nil,<br>    false,<br>},</pre><p>With our new mock, there is no need to auto-generate our mocks or use complex testing frameworks, the Go programing language makes testing and mocking easy straight out of the box.</p><h3>Problems Be Gone</h3><p>Now that we are returning the concrete Store pointer type, any new methods that are added do not require large refactoring of our test as they are only using the interfaces that they require. <em>Problem one solved</em>.</p><p>If we add a method that we need in a function we’ll have to add it to our interface:</p><pre>type UserTeamGetAdder interface {<br>    UserTeamGetter<br>    AddUserToTeam(teamID, userID int) error<br>}</pre><pre>SomeHandler(ctx context.Context, store UserTeamGetAdder, userID int) error {<br>    // ...<br>}</pre><p>This will case our tests to fail, but the Go compiler will lead you the way:</p><pre>cannot use &amp;(store literal) (value of type *userTeamMock) as UserTeamGetAdder value in argument to SomeHandler: missing method AddUserToTeam</pre><p>Rather than refactoring all of our test cases we can just add the method to our mock:</p><pre>func (m *userTeamMock) AddUserToTeam(teamID, userID int) (*db.User, error) {<br>    if m != nil &amp;&amp; m.getUserFn != nil {<br>        return m.addUserToTeamFn(teamID, userID)<br>    }</pre><pre>    return &amp;db.User{Firstname: &quot;foo&quot;, Lastname: &quot;bar&quot;}, nil<br>}</pre><p>All our test will now pass without changing any of our test code, we’re only left with adding more test cases. <em>Problem 2 solved</em>.</p><p>We’ve also avoided any <a href="https://en.wikipedia.org/wiki/Magic_string">magic strings</a> which makes any refactoring required a lot easier by utilizing compiler errors (and other Go tools like <a href="https://pkg.go.dev/golang.org/x/tools/gopls">gopls LSP</a>) rather than runtime errors. <em>Problem 3 solved</em>.</p><h3>Final Thoughts</h3><p>Some of the reasons we enjoy the Go Programming Language is that it’s easy to learn, concise, maintainable and very readable.</p><p>But sometimes we still make it hard for ourselves as software engineers with many design patterns we’ve inherited along the way.</p><p>Go’s simplicity challenges us to think differently; and questions whether we really need framework X or framework Y; maybe the standard library that Go provides will be enough?</p><blockquote>“Simplicity is complicated”<br>- Rob Pike</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f952869e34f5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mitti-engineering/flexible-mocking-for-testing-in-go-f952869e34f5">Flexible mocking for testing in Go</a> was originally published in <a href="https://medium.com/mitti-engineering">Mitti Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Node.js is Good; Go is Better]]></title>
            <link>https://medium.com/mitti-engineering/node-js-is-good-go-is-better-e6a743ba2012?source=rss-94b2f66fc7cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6a743ba2012</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[Roger Chapman]]></dc:creator>
            <pubDate>Wed, 15 Jan 2020 22:17:51 GMT</pubDate>
            <atom:updated>2020-01-15T22:17:51.477Z</atom:updated>
            <content:encoded><![CDATA[<p>SafetyCulture has a microservice architecture deployed on <a href="https://kubernetes.io/">Kubernetes</a> (AWS <a href="https://aws.amazon.com/eks/">EKS</a>). When we started this architecture all our services were written, predominantly, in <a href="https://nodejs.org/en/">Node.js</a>.</p><p>In the early days of our product, Node.js was great; it allowed teams to build services quickly and share a lot of common libraries. Data structures were stored as JSON, and Frontend/Backend development could all be done in a common language: JavaScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0EHIutMszQiNPcqZ7g3Nig.png" /></figure><p>As time passed, our codebase grew, as well as our Engineering team. Cracks started to appear under the fast-paced growth of the company, product and our microservices. Schema-less JSON in a document store, once our friend, became hard to reason with; and flavours of JavaScript (CoffeeScript, ES5, ES6/7, TypeScript) added a lot of technical debt.</p><p>By no means a <a href="https://www.phrases.org.uk/meanings/silver-bullet.html">silver bullet</a>, we decided to try <a href="https://golang.org/">Go</a>, along with other technologies (<a href="https://www.postgresql.org/">Postgres</a>, <a href="https://developers.google.com/protocol-buffers">Protocol Buffers</a> and <a href="https://grpc.io/">gRPC</a>). You can read more about this decision on: <a href="https://medium.com/safetycultureengineering/why-go-is-a-good-language-for-microservices-b4fc6a5a532c">Why Go is a good language for microservices</a>.</p><h3>Refactor</h3><p>Comparing a Node.js service to a Go service can be subjective, as no two distinct services have the same API, SLAs, network traffic, workload etc… unless it’s exactly the same service.</p><p>To improve the maintainability of one of our services; we decided to refactor the service from Node.js to Go. The API would have a new gRPC endpoint (for newer clients) but would still expose the existing HTTP/JSON API for backward compatibility.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZbY6U5YACyzMg2BnhBRDgQ.png" /><figcaption>NodeJS refactored to Go</figcaption></figure><p>Deploying the new Go service showed instant results in performance: the <a href="https://grafana.com/">Grafana</a> graph shows the metrics for the existing HTTP/JSON API; the gRPC endpoint may see a further improvement as it will remove the need to marshal/unmarashal the JSON (no data yet on this, but the JSON API calls the internal gRPC API).</p><p>Latency was reduced from 10ms (still really good) to 3ms (this service gets called multiple times per user request so every millisecond counts). CPU usage was cut in half (actually more) and Memory usage was reduced from 180MB to 40MB (per pod).</p><p>This refactor has improved the user experience (latency) and enabled the service to scale farther than before.</p><p>What’s your experience? Have you seen a performance change by migrating any of your services to Go?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6a743ba2012" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mitti-engineering/node-js-is-good-go-is-better-e6a743ba2012">Node.js is Good; Go is Better</a> was originally published in <a href="https://medium.com/mitti-engineering">Mitti Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Proxy gRPC-Web directly in your Go Server (without envoy)]]></title>
            <link>https://medium.com/mitti-engineering/proxy-grpc-web-directly-in-your-go-server-without-envoy-7fbec326cb21?source=rss-94b2f66fc7cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fbec326cb21</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[http2]]></category>
            <category><![CDATA[grpc]]></category>
            <category><![CDATA[grpc-web]]></category>
            <dc:creator><![CDATA[Roger Chapman]]></dc:creator>
            <pubDate>Fri, 26 Jul 2019 07:11:06 GMT</pubDate>
            <atom:updated>2019-08-27T00:34:04.188Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>“gRPC-Web clients connect to gRPC services via a special gateway proxy: the current version of the library uses Envoy by default, in which gRPC-Web support is built-in.” — </em><strong>official </strong><a href="https://github.com/grpc/grpc-web"><strong>gRPC-Web</strong></a><strong> docs.</strong></blockquote><p>For production we can just enable the envoy.grpc_web filter and we are good to go.</p><p>But for development I wanted to create a gRPC server that engineers could install via a single binary and not have to run anything extra (like envoy running in docker).</p><h3>gRPC-Web Wrapper</h3><p>Prior to the release of the official gRPC-Web implementation the good guys at Improbable Engineering had created their own version of gRPC-Web; they also have a package that implements the gRPC-Web spec as a wrapper around a gRPC Go Server.</p><p>Turns out that, with a little extra configuration, it can be made compatible with the official gRPC-Web client:</p><pre>grpcServer := grpc.Server()<br>grpcWebServer := grpcweb.WrapServer(grpcServer)<br>httpServer = &amp;http.Server{<br>  Handler: h2c.NewHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { <br>    if r.ProtoMajor == 2 {<br>      grpcWebServer.ServeHTTP(w, r)<br>    } else { <br>      w.Header().Set(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;)<br>      w.Header().Set(&quot;Access-Control-Allow-Methods&quot;, &quot;POST, GET, OPTIONS, PUT, DELETE&quot;)<br>      w.Header().Set(&quot;Access-Control-Allow-Headers&quot;, &quot;Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, X-User-Agent, X-Grpc-Web&quot;)<br>      w.Header().Set(&quot;grpc-status&quot;, &quot;&quot;)<br>      w.Header().Set(&quot;grpc-message&quot;, &quot;&quot;) <br>      if grpcWebServer.IsGrpcWebRequest(r) {<br>        grpcWebServer.ServeHTTP(w, r) <br>      }<br>    }<br>  }), &amp;http2.Server{}),<br>}</pre><p><strong>Note:</strong> Were also using the golang.org/x/net/http2/h2c package to allow HTTP/2 over cleartext as we are also listening for HTTP/1.1 requests on the same port without TLS. This is not recommended for production, but means we don&#39;t require certificates during development.</p><h3>Debugging gRPC-Web on the wire</h3><p>For our frontend engineers they rely on chrome devtools to view network traffic, but for gRPC-Web it appears as a base64 string; not very useful.</p><p>So we created <a href="https://github.com/SafetyCulture/grpc-web-devtools">gRPC-Web Dev Tools</a> a network like extension for Chrome that allows you to view the gRPC-Web requests and responses de-serialized to JSON objects; much better:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XCmk2-e03JiE4mbm.png" /></figure><p><em>Originally published on the </em><a href="https://rogchap.com/2019/07/26/in-process-grpc-web-proxy/"><em>authors personal blog</em></a><em> on July 26, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fbec326cb21" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mitti-engineering/proxy-grpc-web-directly-in-your-go-server-without-envoy-7fbec326cb21">Proxy gRPC-Web directly in your Go Server (without envoy)</a> was originally published in <a href="https://medium.com/mitti-engineering">Mitti Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generating a mock gRPC server in Go]]></title>
            <link>https://medium.com/mitti-engineering/mocking-grpc-in-go-542cab6e012b?source=rss-94b2f66fc7cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/542cab6e012b</guid>
            <category><![CDATA[protocol-buffers]]></category>
            <category><![CDATA[grpc]]></category>
            <category><![CDATA[mocking]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Roger Chapman]]></dc:creator>
            <pubDate>Tue, 25 Jun 2019 12:20:10 GMT</pubDate>
            <atom:updated>2019-08-02T08:06:56.660Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the huge benefits of using gRPC is the ability to autogenerate our client and server stubs from the protocol buffer definitions.</p><p>In the same way, we can we generate our own code by building a plugin for the protocol buffer compiler (protoc).</p><p>The plugin we’re creating is going to auto-generate gRPC response messages so that we can build a mock gRPC server in Go (Golang).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DX-cx1XS414_F4A63ufPfA.png" /><figcaption>Based on original artwork from <a href="http://reneefrench.blogspot.com/">Renee French</a></figcaption></figure><h3>Goal</h3><p>Given the following proto file:</p><pre>service MyService {<br>  rpc Get(Request) returns (Response) {}<br>}</pre><pre>message Request {}</pre><pre>message Response {<br>  string id = 1;<br>}</pre><p>We want to be able to generate something like:</p><pre>func (m *MyServiceMock) Get(context.Context, *Request) (*Response, error) {<br>  return Response{Id: &quot;f267332d-0d9a-4220-b055-63b661b600db&quot;}, nil<br>}</pre><h3>Creating a protoc Go plugin</h3><p>All we have to do is implement the Plugin interface defined in protobuf/protoc-gen-go/generator:</p><pre>type grpcmock struct {<br>  *generator.Generator<br>}</pre><pre>func New() generator.Plugin {<br>  return &amp;grpcmock{}<br>}</pre><pre>func (g *grpcmock) Name() string {<br>  return &quot;grpcmock&quot;<br>}</pre><pre>func (g *grpcmock) Init(gen *generator.Generator) {<br>  g.Generator = gen<br>}</pre><pre>func (g *grpcmock) Generate(file *generator.FileDescriptor) {<br>  for _, service := range file.FileDescriptorProto.Service {<br>    g.mockService(file, service)<br>  }<br>}</pre><pre>func (g *grpcmock) GenerateImports(file *generator.FileDescriptor) {<br>  imports := generator.NewPluginImports(g.Generator)<br>  imports.GenerateImports(file)<br>}</pre><h3>Mocking a Service</h3><p>Now that we have satisfied our Plugin interface we can implement our mock services:</p><pre>func (g *grpcmock) mockService(file *generator.FileDescriptor, service *descriptor.ServiceDescriptorProto) {<br>  origServName := service.GetName()<br>  servName := generator.CamelCase(origServName)<br>  servTypeName := fmt.Sprintf(&quot;%sMock&quot;, servName)</pre><pre>  g.P(`type `, servTypeName, ` struct {}`)<br>  g.P()<br>  for _, method := range service.Method {<br>    g.mockMethod(servTypeName, method)<br>  }<br>}</pre><p>This gives us our mock struct that we can create our methods from to implement the gRPC interface for our service:</p><pre>func (g *grpcmock) mockMethod(servTypeName string, method *descriptor.MethodDescriptorProto) {<br>  methName := generator.CamelCase(method.GetName())<br>  inType := g.typeName(method.GetInputType())<br>  outType := g.typeName(method.GetOutputType())</pre><pre>  g.P(`func (m *`, servTypeName, `) `, methName, `(context.Context, *`, inType, `) (*`, outType, `, error){`)<br>  g.In()</pre><pre>  msg := g.objectNamed(method.GetOutputType()).(*generator.Descriptor)<br>  g.P(`res := `)<br>  g.generateMockMessage(msg)<br>  g.P(`return res, nil`)</pre><pre>  g.Out()<br>  g.P(`}`)<br>}</pre><p>The last part is to generate the response message and it’s fields:</p><pre>func (g *grpcmock) generateMockMessage(msg *generator.Descriptor) {<br>  msgName := g.TypeName(msg)<br>  g.P(msgName, `{`)<br>  g.In()</pre><pre>  for _, field := range msg.Field {<br>    fieldName := g.GetFieldName(msg, field)<br>    if field.IsString() {<br>      g.P(fieldName, `: &quot;f267332d-0d9a-4220-b055-63b661b600db&quot;,`)<br>    }<br>  }</pre><pre>  g.Out()<br>  g.P(`}`)<br>}</pre><p>For the above string field we are returning a hard coded value, but we can easily replace this for auto-generated values.</p><h3>Building our plugin</h3><p>All that is left to do is wire up our plugin (errors ignored for brevity):</p><pre>func main() {<br>  gen := generator.New()<br>  data, _ := ioutil.ReadAll(os.Stdin)</pre><pre>  proto.Unmarshal(data, gen.Request)<br>  gen.CommandLineParameters(gen.Request.GetParameter())</pre><pre>  gen.WrapTypes()<br>  gen.SetPackageNames()<br>  gen.BuildTypeNameMap()<br>  gen.GeneratePlugin(plugin.New())</pre><pre>  for i := 0; i &lt; len(gen.Response.File); i++ {<br>  gen.Response.File[i].Name = proto.String(strings.Replace(*gen.Response.File[i].Name, &quot;.pb.go&quot;, &quot;.mock.go&quot;, -1))<br>  }</pre><pre>  data, _ = proto.Marshal(gen.Response)<br>  os.Stdout.Write(data)<br>}</pre><p>By convention of protoc plugins our binary must be prefixed with protoc-gen- so in our case we are going to build our binary as protoc-gen-gogrpcmock.</p><p>Now we can use our plugin to generate the mock implementation of our service:</p><pre>$ protoc -I. --go_out=plugin=grpc=:/out --gogrpcmock_out=:/out src/*.proto</pre><h3>Usage</h3><p>Now that we have our generated output we can use it (along with the gRPC output stub) to build a mock gRPC Server:</p><pre>grpcServer := grpc.NewServer()<br>myservice.RegisterMyServiceServer(s, &amp;myservice.MyServiceMock{}) lis, _ := net.Listen(&quot;tcp&quot;, 50501)<br>grpcServer.Serve(lis)</pre><h3>Batteries included</h3><p>If you are looking for a complete solution to generate mock data for your gRPC service(s) then you can take a look at our <a href="https://github.com/SafetyCulture/s12-proto/tree/master/protobuf/protoc-gen-gogrpcmock">gRPC Mock Generator</a>; just install via go get and start using the protoc-gen-gogrpcmock plugin<br>(FYI: I use the <a href="https://github.com/gogo/protobuf">Gogo</a> version of protobuf for this plugin)</p><pre>$ go get -u github.com/SafetyCulture/s12-proto/protobuf/protoc-gen-gogrpcmock<br>$ protoc -I. --gogo_out= plugin = grpc =:/out --gogrpcmock_out=:/out src/*.proto</pre><p><em>Originally published at </em><a href="https://rogchap.com/2019/06/25/mocking-grpc-in-go/"><em>https://rogchap.com</em></a><em> on June 25, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=542cab6e012b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mitti-engineering/mocking-grpc-in-go-542cab6e012b">Generating a mock gRPC server in Go</a> was originally published in <a href="https://medium.com/mitti-engineering">Mitti Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rebuilding for Scale]]></title>
            <link>https://medium.com/mitti-engineering/rebuilding-for-scale-521c0632f40e?source=rss-94b2f66fc7cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/521c0632f40e</guid>
            <category><![CDATA[grpc]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[tech-talk]]></category>
            <dc:creator><![CDATA[Roger Chapman]]></dc:creator>
            <pubDate>Fri, 15 Mar 2019 08:45:28 GMT</pubDate>
            <atom:updated>2019-03-15T08:47:19.860Z</atom:updated>
            <content:encoded><![CDATA[<h3>Rebuilding for Scale (Video)</h3><p>Tech talk for Sydney University Computing Society (<a href="http://syncs.org.au/">SYNCS</a>)</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FPLnlZt2vSYU%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DPLnlZt2vSYU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FPLnlZt2vSYU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d3db2fd71dd18eb38f8c421469482c5/href">https://medium.com/media/9d3db2fd71dd18eb38f8c421469482c5/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RJZvLs8VD-Jd2bTwJtgWNQ.png" /><figcaption>Presentation slides</figcaption></figure><p>Presentation slides are available <a href="https://docs.google.com/presentation/d/e/2PACX-1vSnSmWYhYaOkeL_fehsGuUDW2-4-RqTkoOIPVqYG0xRIqFdEWzMzdya-1P7HXkcU-dj9yGi252AZxAV/pub?start=false&amp;loop=false&amp;delayms=3000">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=521c0632f40e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mitti-engineering/rebuilding-for-scale-521c0632f40e">Rebuilding for Scale</a> was originally published in <a href="https://medium.com/mitti-engineering">Mitti Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why we moved our graphQL server from Node.js to Golang]]></title>
            <link>https://medium.com/mitti-engineering/why-we-moved-our-graphql-server-from-node-js-to-golang-645b00571535?source=rss-94b2f66fc7cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/645b00571535</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Roger Chapman]]></dc:creator>
            <pubDate>Wed, 27 Jun 2018 00:25:35 GMT</pubDate>
            <atom:updated>2018-06-27T00:37:34.453Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*vzYIMVLp579pUCvs7xhyvg.png" /><figcaption>Logo from <a href="https://github.com/graph-gophers/graphql-go">graph-gophers</a></figcaption></figure><h3>In the beginning: Apollo Server</h3><p>When it comes to building a graphQL server, almost everyone looks to <a href="https://github.com/apollographql/apollo-server">Apollo Server</a>; we were no different. Apollo allowed us to get a graphQL server up and running really quickly. We loved being able to <a href="https://www.apollographql.com/docs/apollo-server/v2/features/mocking.html">return mock data</a> almost instantly to our mobile/frontend engineers.</p><h3>Our graphQL server began to grow</h3><p>At <a href="https://safetyculture.com/">SafetyCulture</a> we have a microservice architecture, so our graphQL server only orchestrates data to our resolvers; no business logic here. However, our graphQL schema grew and grew and became hard to manage.</p><h4>Magic strings</h4><p>Most graphQL examples use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals">ES2015 template literals</a> to define the schema, but over time this get hard to read and refactor.</p><pre>// This looks simple, but what happens when you have 50+ types?<br>const typeDefs = `<br>  type Query {<br>    hello: String<br>  }<br>`;</pre><h4>What the arg?</h4><p>Resolvers also became hard to manage too and new engineers had a hard time figuring out what arguments were being passed to each resolver.</p><pre>// Resolvers are just one big object, this gets out of control.<br>const resolvers = {<br>  Query: {<br>    hello: (root, args, context) =&gt; {<br>      return &#39;Hello world!&#39;;<br>    },<br>  },<br>};</pre><p>Notice root , arg , and context ? What properties do these objects have? This is what a lot of our resolves ended up looking like and confused so many engineers:</p><pre>// Nobody knows where these args come from!<br>setSomeValue: (_, { id, myValue }, { userId, someService }) =&gt; {<br>  return someService.setSomeValue(userId, id, myValue);<br>},</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*dKKlErTwISoeZCeRugRFDA.png" /><figcaption>Node.js vs Golang minimap</figcaption></figure><h3>Testing resolvers</h3><p>In the Node.js world testing resolvers was also hard; managing large objects, the resolver arguments and dependent services made it almost impossible. At least we could still test the actual graphQL queries. Hacker Noon has a great <a href="https://hackernoon.com/extensive-graphql-testing-57e8760f1c25">post on this</a>.</p><h4>JSON mapping</h4><p>Our internal microservices use <a href="https://grpc.io/">gRPC</a> so we already had our messages defined in <a href="https://developers.google.com/protocol-buffers/">Protocol Buffers</a>. Apollo Server can auto map object fields to resolvers, so we ended up with a lot of ugly code that would unmarshall the data to JSON and then map to an object so we could <em>auto</em> resolve. Admittedly, we should just fix this problem in the Node.js; it was just a bad pattern, but it was one more thing we could fix with the rebuild.</p><h3>Go, Go everywhere</h3><p>Our graphQL server talks to many internal services; all these services are written in Go, so it was also a natural goal to have our edge service also in Go.</p><h4>GraphQL in Go</h4><p>For our Golang implementation we used <a href="https://github.com/graph-gophers/graphql-go">graph-gophers/graphql-go</a>. It has support to parse the GraphQL schema language and give us schema type checking against our resolvers; we can now see if we have a missing resolver at compile time, and not have to debug at runtime to find a typo!</p><h4>Schema definitions</h4><p>Instead of long template literals we now define our schema in individual .gql files, this means we can have nicely formatted (easy to read) types using an <a href="https://marketplace.visualstudio.com/items?itemName=kumar-harsh.graphql-for-vscode">IDE plugin</a> . Using $ go generate schema and <a href="https://github.com/jteeuwen/go-bindata/">jteeuwen/go-bindata</a> it’s easy to generate our schema during development.</p><pre>//go:generate go-bindata -ignore=\.go -pkg=schema -o=bindata.go ./...</pre><pre>package schema</pre><pre>import &quot;bytes&quot;</pre><pre>// GetRootSchema gets the GraphQL schema from the generated bindata<br>func GetRootSchema() string {<br>  buf := bytes.Buffer{}<br>  for _, name := range AssetNames() {<br>    b := MustAsset(name)<br>    buf.Write(b)</pre><pre>    // Add a newline if the file does not end in a newline.<br>    if len(b) &gt; 0 &amp;&amp; b[len(b)-1] != &#39;\n&#39; {<br>      buf.WriteByte(&#39;\n&#39;)<br>    }<br>  }<br>  return buf.String()<br>}</pre><h4>Type safe resolvers</h4><p>Because Golang is <a href="https://en.wikipedia.org/wiki/Type_safety">type safe</a> all our resolvers had concrete arguments and a simple function that can easily be tested.</p><pre>func (r *Resolver) SetSomeValue(ctx context.Context, args struct {<br>  ID      graphql.ID<br>  MyValue *bool<br>}) (*MyReturnType, error) {<br>  someService := utils.GetSomeServiceFromContext(ctx)<br>  userID := utils.GetUserIDFromContext(ctx)<br>  return someService.SetSomeValue(userID, string(args.ID), args.MyValue)}<br>}</pre><h4>Resource utilisation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*49GHh0LPmzJPCS3oxd4dHQ.png" /><figcaption>Memory Utilisation</figcaption></figure><p>As a result of deploying the Golang version of our graphQL server there was a significant reduction in memory utilisation within our containers from 55% to only 10%. There was also a drop in CPU utilisation from 30% to under 10%. This means we can adjust our resource reservations in our cluster, in turn reducing the cost of instances needed, thus makes the Foundational Engineering and Finance team happy.</p><h3>Future</h3><p>With the move to Golang for our GraphQL server we believe we have a more scalable and manageable service than we had before. The performance increase (thank to goroutines) was also an added bonus.</p><p>As SafetyCulture grows we’ll continue to invest in the right tools for the task at hand; Golang and GraphQL are high on our list.</p><p>If you’re interested in helping us build something that truly impacts people’s lives and get to do it using the best technologies, we’re always on the lookout for <a href="https://safetyculture.com/careers/">people that are up for a challenge</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=645b00571535" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mitti-engineering/why-we-moved-our-graphql-server-from-node-js-to-golang-645b00571535">Why we moved our graphQL server from Node.js to Golang</a> was originally published in <a href="https://medium.com/mitti-engineering">Mitti Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The best welcome gifts for your guests]]></title>
            <link>https://medium.com/@rogchap/the-best-welcome-gifts-for-your-guests-2ae63bd895d6?source=rss-94b2f66fc7cb------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ae63bd895d6</guid>
            <category><![CDATA[guest]]></category>
            <category><![CDATA[travel]]></category>
            <category><![CDATA[airbnb]]></category>
            <category><![CDATA[how-to]]></category>
            <dc:creator><![CDATA[Roger Chapman]]></dc:creator>
            <pubDate>Thu, 17 Nov 2016 04:49:05 GMT</pubDate>
            <atom:updated>2017-02-22T05:12:17.822Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome gifts are not the norm in the world of <a href="https://www.airbnb.com.au/">Airbnb</a> and, as a host, there’s definitely no expectation that you leave one. Of course, this is exactly what makes a welcome gift such a powerful gesture and strong predictor of a glowing review: it creates a wonderful first impression.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GSIdyEyL6nphaWBJc27ctQ.jpeg" /></figure><p><strong>SURPRISE SCIENCE TIME!</strong> (Because there’s no better way to back up our advice than with facts)</p><p>Let’s take a speedy but informative look at the science of first impressions. As human beings, we take only a matter of milliseconds to form a first impression. Interestingly, despite this high speed decision making, first impressions are incredibly difficult to change: once our mind is made up about something, we need a mountain of contradictory evidence before we’ll consider altering our initial opinion.</p><p>‘Ok,’ you think to yourself. ‘This is interesting and all, but how is it relevant to my Airbnb property?’ Because nothing says ‘I am a thoughtful host who goes the extra mile’ quite like a surprise welcome gift. And isn’t that a positive first impression? Furthermore, thanks to science, this positive assessment will be your biggest asset if something unforeseen happens during a stay. You take a day to reply to an email? ‘So out of character’, your guests will think. A cafe you recommended in your guide book has shut down? ‘Oh no, they mustn’t have known.’ See where we’re going with this?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/0*FbC8Y2_ERL_5fgoU.jpg" /></figure><p>With surprise science time now complete and the benefits of welcome gifts clearly established, the next logical question is what kind of gifts to leave. For us, the right gift is all about striking the balance between thoughtfulness (important for your guests) and affordability (important for you). Here are our top picks:</p><p><strong>Something local</strong></p><p>Most people don’t travel to Italy to eat dim sum, to France to drink the beer or to The Big Pineapple to munch on a coconut. One of the big draw cards of travel is discovering the things each place is great at or famous for. As such, it’s always a winning idea to gift your guests with something from your surrounds. Obviously this will differ depending on where you live, but how about a bottle of the good stuff from your closest winery, some home-made jam from your local farmers market or a deliciously crusty loaf of bread from your nearest bakery?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Wp-FsH8inhIOQt0s.jpg" /></figure><p><strong>Something seasonal</strong></p><p>Have you got guests staying over Christmas? Leave a festive fruit cake. A booking for the Easter long weekend? Hide a little cachet of Easter eggs. Someone staying over on Australia Day? Go on, leave them a lamington. This same idea works well for the seasons too. Start of spring? Nothing better than a bunch of flowers. The middle of winter? A tin of fancy hot chocolate will do very nicely.</p><p><strong>Something personal</strong></p><p>You know how we always harp on about Airbnb having the edge over hotels because it offers a warmer, more personal experience? Gift giving is an excellent time to capitalise on this, leaving hotel slippers and packet soaps looking cold in comparison. Obviously this can be a tricky one to pull off — you’ll probably never know enough about your guests to know their specific tastes — so go general. Is it their first time to Australia? Leave some Vegemite. Do they have young kids? Leave a small toy. Are they on their honeymoon? Leave a bottle of champagne to help them celebrate. See? Easy peasy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hgL2Z-3kHPtPXX2N.jpg" /></figure><p>Of course, now is as good a time as any to mention that, at your direction, we can leave little welcome gifts as part of our service. So go on, make that extra effort and stand out from the crowd. Your glowing reviews will be all the thanks you need.</p><p><a href="https://hometime.io/"><em>Hometime</em></a><em> provides the complete suite of services for your Airbnb, allowing you to increase your income without lifting a finger. Our expertise ensures your property is booked for more nights at the best price and that each guest has a wonderful stay. It’s your home - we just help it reach its full potential.</em></p><p><em>Originally published at </em><a href="https://blog.kayla.com.au/the-best-welcome-gifts-for-your-guests/"><em>blog.kayla.com.au</em></a><em> on November 17, 2016. by @Kirsty_Fanton</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ae63bd895d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>