Slide 1

Slide 1 text

On Ferrets and Gophers Introducing FerretDB Alexey Palazhchenko GDG Berlin Golang 2022-01-12

Slide 2

Slide 2 text

About me

Slide 3

Slide 3 text

About me

Slide 4

Slide 4 text

About me

Slide 5

Slide 5 text

About me

Slide 6

Slide 6 text

About me

Slide 7

Slide 7 text

About me

Slide 8

Slide 8 text

MongoDB

Slide 9

Slide 9 text

MongoDB • Great Developer Experience

Slide 10

Slide 10 text

MongoDB • Great Developer Experience • Used to send iPads to community members

Slide 11

Slide 11 text

MongoDB • Great Developer Experience • Used to send iPads to community members • Reliability

Slide 12

Slide 12 text

MongoDB • Great Developer Experience • Used to send iPads to community members • Reliability • Performance

Slide 13

Slide 13 text

MongoDB • Great Developer Experience • Used to send iPads to community members • Reliability • Performance • Scalability

Slide 14

Slide 14 text

MongoDB • Great Developer Experience • Used to send iPads to community members • Reliability • Performance • Scalability

Slide 15

Slide 15 text

MongoDB • Great Developer Experience • Used to send iPads to community members • Reliability • Performance • Scalability • … does too much?

Slide 16

Slide 16 text

MongoDB • Great Developer Experience • Used to send iPads to community members • Reliability • Performance • Scalability • … does too much? • License change

Slide 17

Slide 17 text

Not a legal advice

Slide 18

Slide 18 text

Not a legal advice

Slide 19

Slide 19 text

AGPL v3 SSPL

Slide 20

Slide 20 text

AGPL v3 • «If you modify the Program» SSPL

Slide 21

Slide 21 text

AGPL v3 • «If you modify the Program» • «All users interacting with it remotely through a computer network» SSPL

Slide 22

Slide 22 text

AGPL v3 • «If you modify the Program» • «All users interacting with it remotely through a computer network» • «Interacting» is not a term SSPL

Slide 23

Slide 23 text

AGPL v3 • «If you modify the Program» • «All users interacting with it remotely through a computer network» • «Interacting» is not a term • «Corresponding Source» SSPL

Slide 24

Slide 24 text

AGPL v3 • «If you modify the Program» • «All users interacting with it remotely through a computer network» • «Interacting» is not a term • «Corresponding Source» • «Including scripts to control those activities» SSPL

Slide 25

Slide 25 text

AGPL v3 • «If you modify the Program» • «All users interacting with it remotely through a computer network» • «Interacting» is not a term • «Corresponding Source» • «Including scripts to control those activities» • «If you make the functionality of the Program» SSPL

Slide 26

Slide 26 text

AGPL v3 • «If you modify the Program» • «All users interacting with it remotely through a computer network» • «Interacting» is not a term • «Corresponding Source» • «Including scripts to control those activities» • «If you make the functionality of the Program» • «available to third parties as a service» SSPL

Slide 27

Slide 27 text

AGPL v3 • «If you modify the Program» • «All users interacting with it remotely through a computer network» • «Interacting» is not a term • «Corresponding Source» • «Including scripts to control those activities» • «If you make the functionality of the Program» • «available to third parties as a service» • «includes, without limitation, […]»
 very broad, but not very clear SSPL

Slide 28

Slide 28 text

AGPL v3 • «If you modify the Program» • «All users interacting with it remotely through a computer network» • «Interacting» is not a term • «Corresponding Source» • «Including scripts to control those activities» • «If you make the functionality of the Program» • «available to third parties as a service» • «includes, without limitation, […]»
 very broad, but not very clear • «Service Source Code» SSPL

Slide 29

Slide 29 text

AGPL v3 • «If you modify the Program» • «All users interacting with it remotely through a computer network» • «Interacting» is not a term • «Corresponding Source» • «Including scripts to control those activities» • «If you make the functionality of the Program» • «available to third parties as a service» • «includes, without limitation, […]»
 very broad, but not very clear • «Service Source Code» • «including, without limitation, management software, user interfaces, application program interfaces, […], all such that a user could run an instance of the service using the Service Source Code you make available.» SSPL

Slide 30

Slide 30 text

SSPL FAQ

Slide 31

Slide 31 text

SSPL FAQ

Slide 32

Slide 32 text

The SSPL is Not 
 an Open Source License

Slide 33

Slide 33 text

The SSPL is Not 
 an Open Source License https://opensource.org/node/1099

Slide 34

Slide 34 text

Protocol speci fi cation license

Slide 35

Slide 35 text

FerretDB

Slide 36

Slide 36 text

FerretDB • MongoDB protocol proxy for PostgreSQL

Slide 37

Slide 37 text

FerretDB • MongoDB protocol proxy for PostgreSQL • Accepts unmodi fi ed client connections

Slide 38

Slide 38 text

FerretDB • MongoDB protocol proxy for PostgreSQL • Accepts unmodi fi ed client connections • Parses BSON queries

Slide 39

Slide 39 text

FerretDB • MongoDB protocol proxy for PostgreSQL • Accepts unmodi fi ed client connections • Parses BSON queries • Converts them to SQL

Slide 40

Slide 40 text

FerretDB • MongoDB protocol proxy for PostgreSQL • Accepts unmodi fi ed client connections • Parses BSON queries • Converts them to SQL • Sends them to PostgreSQL

Slide 41

Slide 41 text

FerretDB • MongoDB protocol proxy for PostgreSQL • Accepts unmodi fi ed client connections • Parses BSON queries • Converts them to SQL • Sends them to PostgreSQL • Apache 2.0 licensed

Slide 42

Slide 42 text

PostgreSQL

Slide 43

Slide 43 text

PostgreSQL • Reliable

Slide 44

Slide 44 text

PostgreSQL • Reliable • Performant

Slide 45

Slide 45 text

PostgreSQL • Reliable • Performant • Scalable

Slide 46

Slide 46 text

PostgreSQL • Reliable • Performant • Scalable • Feature-rich

Slide 47

Slide 47 text

MangoDB Day

Slide 48

Slide 48 text

MangoDB Day

Slide 49

Slide 49 text

Why Go 1.18?

Slide 50

Slide 50 text

Why Go 1.18? Generics

Slide 51

Slide 51 text

Why Go 1.18? Generics Fuzzing

Slide 52

Slide 52 text

Why Go 1.18? Generics Fuzzing

Slide 53

Slide 53 text

Generics

Slide 54

Slide 54 text

Generics • Generics do not work there; let's go back to interfaces

Slide 55

Slide 55 text

Generics • Generics do not work there; let's go back to interfaces • Let me extract a small example for meetup

Slide 56

Slide 56 text

Generics • Generics do not work there; let's go back to interfaces • Let me extract a small example for meetup • Hm, that's not that bad

Slide 57

Slide 57 text

BSON Document

Slide 58

Slide 58 text

BSON Document • Ordered map

Slide 59

Slide 59 text

BSON Document • Ordered map • Keys – string, values – any BSON value, including other documents

Slide 60

Slide 60 text

BSON Document • Ordered map • Keys – string, values – any BSON value, including other documents • The central data structure in FerretDB

Slide 61

Slide 61 text

Interfaces type BSONType interface { bsontype() // sealed } type Int int func (Int) bsontype() {} type String string func (String) bsontype() {}

Slide 62

Slide 62 text

Interfaces type BSONType interface { bsontype() // sealed } type Int int func (Int) bsontype() {} type String string func (String) bsontype() {} type Document struct { m map[string]BSONType keys []string } func (*Document) bsontype() {}

Slide 63

Slide 63 text

Interfaces func (d *Document) Set(key string, value BSONType) { if _, ok := d.m[key]; !ok { d.keys = append(d.keys, key) } d.m[key] = value }

Slide 64

Slide 64 text

Interfaces d.Set("foo", Int(42))

Slide 65

Slide 65 text

Interfaces d.Set("foo", Int(42)) d.Set("qux", nil)

Slide 66

Slide 66 text

Generics type BSONType interface { int | string | *Document }

Slide 67

Slide 67 text

Generics type BSONType interface { int | string | *Document } type Document struct { m map[string]any keys []string }

Slide 68

Slide 68 text

Generics func DocumentSet[T BSONType](d *Document, key string, value T) { if _, ok := d.m[key]; !ok { d.keys = append(d.keys, key) } d.m[key] = value }

Slide 69

Slide 69 text

Generics DocumentSet(d, "foo", 42)

Slide 70

Slide 70 text

Generics DocumentSet(d, "foo", 42) // DocumentSet(d, "qux", nil)

Slide 71

Slide 71 text

Interfaces func MakeDocument(pairs ...BSONType) (*Document, error) { l := len(pairs) if l%2 != 0 { return nil, fmt.Errorf("%d arguments", l)

Slide 72

Slide 72 text

Interfaces

Slide 73

Slide 73 text

Interfaces MakeDocument(String("invalid number of arguments"))

Slide 74

Slide 74 text

Interfaces MakeDocument(String("invalid number of arguments")) MakeDocument(Int(42), String("invalid key type"))

Slide 75

Slide 75 text

Interfaces MakeDocument(String("invalid number of arguments")) MakeDocument(Int(42), String("invalid key type")) MakeDocument( String("foo"), Int(42), String("bar"), String("baz"), )

Slide 76

Slide 76 text

Generics

Slide 77

Slide 77 text

Generics func MakeDocument[T BSONType](key string, value T) *Document

Slide 78

Slide 78 text

Generics func MakeDocument[T BSONType](key string, value T) *Document func MakeDocument2[T1, T2 BSONType](key1 string, value1 T1, key2 string, value2 T2) *Document

Slide 79

Slide 79 text

Generics func MakeDocument[T BSONType](key string, value T) *Document func MakeDocument2[T1, T2 BSONType](key1 string, value1 T1, key2 string, value2 T2) *Document func MakeDocument3[T1, T2, T3 BSONType](key1 string, value1 T1, key2 string, value2 T2, key3 string, value3 T3) *Document

Slide 80

Slide 80 text

Generics vs Interfaces

Slide 81

Slide 81 text

Generics vs Interfaces • Better in some aspects

Slide 82

Slide 82 text

Generics vs Interfaces • Better in some aspects • Worse in others

Slide 83

Slide 83 text

Generics vs Interfaces • Better in some aspects • Worse in others • https://github.com/AlekSi/generics-vs-interfaces

Slide 84

Slide 84 text

Use Generics?

Slide 85

Slide 85 text

Use Generics?

Slide 86

Slide 86 text

Fuzzing

Slide 87

Slide 87 text

Fuzzing • testing/quick on steroids

Slide 88

Slide 88 text

Fuzzing • testing/quick on steroids • https://go.dev/blog/fuzz-beta

Slide 89

Slide 89 text

Fuzzing • testing/quick on steroids • https://go.dev/blog/fuzz-beta • MongoDB binary protocol parsing packages

Slide 90

Slide 90 text

Fuzzing • testing/quick on steroids • https://go.dev/blog/fuzz-beta • MongoDB binary protocol parsing packages • They had fuzzing tests even before unit tests

Slide 91

Slide 91 text

Fuzzing func FuzzDocument(f *testing.F) { fuzzBSON( f, documentTestCases, func() BSONType { return new(Document) }, ) }

Slide 92

Slide 92 text

Fuzzing func fuzzBSON(f *testing.F, tcs []testCase, newF func() BSONType) { for _, tc := range tcs { f.Add(tc.b) } // f.Run(tc.name, func(t *testing.T) f.Fuzz(func(t *testing.T, b []byte) {

Slide 93

Slide 93 text

Fuzzing func fuzzBSON(f *testing.F, tcs []testCase, newF func() BSONType) { for _, tc := range tcs { f.Add(tc.b) } // f.Run(tc.name, func(t *testing.T) f.Fuzz(func(t *testing.T, b []byte) { https://github.com/golang/go/issues/47413 👍

Slide 94

Slide 94 text

Fuzzing

Slide 95

Slide 95 text

Fuzzing • Found many bugs in FerretDB

Slide 96

Slide 96 text

Fuzzing • Found many bugs in FerretDB • Found a few bugs in `go test -fuzz`

Slide 97

Slide 97 text

Back to FerretDB

Slide 98

Slide 98 text

Back to FerretDB • Can't wait for Go 1.18 release to make it easier for contributors

Slide 99

Slide 99 text

Back to FerretDB • Can't wait for Go 1.18 release to make it easier for contributors • Speaking of contributors – our community is awesome!

Slide 100

Slide 100 text

Back to FerretDB • Can't wait for Go 1.18 release to make it easier for contributors • Speaking of contributors – our community is awesome! • And FerretDB Inc. started hiring about 1 hour ago

Slide 101

Slide 101 text

Links • https://www.ferretdb.io • https://github.com/FerretDB ⭐ • https://www.ferretdb.io/careers/ • https://github.com/AlekSi • @paaleksey • https://t.me/HowToGoWrong
 (in Russian)