F# goodness for everyday
work
Vladimir Shchur
About me
https://www.linkedin.com/in/uladzimir-shchur-65178968/
F# enthusiast
Employed at Access Softek
Apache Pulsar client library for dotnet
● https://github.com/fsharplang-ru/pulsar-client-dotnet
● Nuget Pulsar.Client
● F# + autogenerated C# protobuf-net classes
● Pipelines.Sockets.Unofficial
● Expecto
● Contributors most welcome!
Apache Pulsar is …
Better Kafka + RabbitMQ
Pulsar features
● Millions of topics
● Unlimited partition size
● Stable latency and high throughput
● Geo-replication
● Tiered storage
● Multitenancy
● Advanced auth
● Proxy
● Pulsar functions
● Pulsar SQL
● Connectors
● Topic compaction
● Delayed delivery
● Schema registry
● Pulsar manager
● K8s friendly
● PAAS on AWS with streamlio
Pulsar drawbacks
● Immature
● No official .NET client
Challenge accepted
● 3 months
● 14 -> 2 members
● 1.5x faster than Java client
● 25x faster than RabbitMQ
● Another .NET client appeared
Let’s start!
Null-safety
Null-safety
Null-safety
Null-safety
● Code is Null-safe by default
● Exceptions are
o Using Unsafe
o Interoperability with C#
Immutability
Code is immutable by default:
No need to worry if message will be mutated
Builder
Immutable builder
Builder problems
● Mutability
● Boilerplate
More on the topic:
https://blog.ploeh.dk/2017/08/14/from-test-data-builders-to-the-identity-functor/
Builder
Identifiers
Identifiers
https://andrewlock.net/using-
strongly-typed-entity-ids-to-
avoid-primitive-obsession-part-1/
Identifiers
https://fsharpforfunandprofit.com/posts/designing-with-types-single-case-dus/
Identifiers with zero overhead
Ordering
Ordering
Best code is no code.
Problem: implement connection state
● Possible statuses: Ready, Connecting, Closing, Closed, Terminated,
Failed, Uninitialized
● If Ready, then ClientCnx object is available for usage, otherwise
unavailable
● Any thread might Read/Update connection state
Problem: implement connection state
Problem: implement connection state
Problem: implement connection state
Locks
MailboxProcessor (Actor)
Queue
Loop
Thread1
Thread2
MailboxProcessor (Actor) with async
Queue
Thread1
Thread2
ThreadPool
Loop
Channel
MailboxProcessor (Actor) with async
Problem: how to unit test?
Problem: how to unit test?
Drawbacks
● Increased coupling.
AcksTracker depends on Consumer (or IConsumer)
● Increased test run time
● Mocking is a code smell
https://medium.com/javascript-scene/mocking-is-a-code-smell-944a70c90a6a
Problem: how to unit test?
One object implementation
One object implementation
Conclusion
● No boilerplate
● No nulls
● No locks
● Concise and safe code
https://fsharpforfunandprofit.com/posts/fsharp-is-the-best-enterprise-language/
Thank you!
https://t.me/fsharp_chat
https://t.me/pro_pulsar
@Lanayx
https://www.slideshare.net/Odin_cool/fsharp-goodness-
for-everyday-work

fsharp goodness for everyday work