Skip to content

Commit

Permalink
docs: update scalable
Browse files Browse the repository at this point in the history
  • Loading branch information
castaneai committed Dec 22, 2023
1 parent d23ae59 commit 1131269
Showing 1 changed file with 30 additions and 33 deletions.
63 changes: 30 additions & 33 deletions docs/scalable.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,49 @@ Want to try it? See Helm chart: [charts/minimatch-scaled](../charts/minimatch-sc

![](./scalable.png)

Since Frontend, Backend and Redis are separate processes,
configure them separately without using `minimatch.NewMinimatchWithRedis`.

## Configure Redis

Use `statestore.NewRedisStore` to configure Redis by passing `rueidis.Client`.

```go
// Create a Redis client
redis, err := rueidis.NewClient(rueidis.ClientOption{
InitAddress: []string{"x.x.x.x:6379"},
})
store := statestore.NewRedisStore(redis)
```

## Configure Frontend

minimatch Frontend mainly provides CreateTicket and WatchAssignment APIs.
No matchmaking implementation is required here. See [Scalable frontend example](../loadtest/cmd/frontend) for an actual example.

## Configure Backend
```go
sv := grpc.NewServer()
pb.RegisterFrontendServiceServer(sv, minimatch.NewFrontendService(store))
```

minimatch Backend fetches the created Ticket and performs matchmaking (In Open Match, this applies to Director and Match Function).
Insert your matchmaking logic here. See [Scalable backend example](../loadtest/cmd/backend) for an actual example.

## Configure Redis
## Configure Backend

A small minimatch would contain Redis within a single process.
However, for scalability, you may want to isolate Redis by passing `rueidis.Client` to create a minimatch StateStore,
which can then be passed to Frontend or Backend.
minimatch Backend fetches the created Ticket and performs matchmaking.
Insert your matchmaking logic here. See [Scalable backend example](../loadtest/cmd/backend) for an actual example.

```go
import (
"github.com/castaneai/minimatch"
"github.com/castaneai/minimatch/pkg/statestore"
"github.com/redis/rueidis"
)

...

// Create a Redis client
redis, err := rueidis.NewClient(rueidis.ClientOption{
InitAddress: []string{"x.x.x.x:6379"},
DisableCache: true,
})
store := statestore.NewRedisStore(redis)

// for frontend
sv := grpc.NewServer()
pb.RegisterFrontendServiceServer(sv, minimatch.NewFrontendService(store))

// for backend
director, err := minimatch.NewDirector(matchProfile, store, minimatch.MatchFunctionSimple1vs1, minimatch.AssignerFunc(dummyAssign))
backend := minimatch.NewBackend()
backend.AddDirector(director)
matchProfile := &pb.MatchProfile{...}
matchFunction := minimatch.MatchFunctionSimple1vs1
assigner := minimatch.AssignerFunc(dummyAssign)
backend, err := minimatch.NewBackend(store, assigner)
backend.AddMatchFunction(matchProfile, matchFunction)
```

## Splitting Redis
## (Optional) Splitting Redis

To distribute the load on Redis, minimatch stores Ticket and Assignment in different keys.
It is also possible to specify a separate Redis Client to store the Assignment. As follows:
If Redis is the bottleneck,
Storing Ticket and Assignment on different Redis servers will result in better load balancing.

```go
redis1, err := rueidis.NewClient(...)
Expand Down

0 comments on commit 1131269

Please sign in to comment.