Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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#...
Apache Pulsar is …
Better Kafka + RabbitMQ
Pulsar features
● Millions of topics
● Unlimited partition size
● Stable latency and high throughput
● Geo-replication
● T...
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 c...
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...
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, Uninitial...
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 co...
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-i...
Thank you!
https://t.me/fsharp_chat
https://t.me/pro_pulsar
@Lanayx
https://www.slideshare.net/Odin_cool/fsharp-goodness-
...
fsharp goodness for everyday work
fsharp goodness for everyday work
Upcoming SlideShare
Loading in …5
×

fsharp goodness for everyday work

516 views

Published on

Story about how fsharp language features help in writing .net client library for apache pulsar.

Published in: Technology
  • Be the first to comment

fsharp goodness for everyday work

  1. 1. F# goodness for everyday work Vladimir Shchur
  2. 2. About me https://www.linkedin.com/in/uladzimir-shchur-65178968/ F# enthusiast Employed at Access Softek
  3. 3. 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!
  4. 4. Apache Pulsar is … Better Kafka + RabbitMQ
  5. 5. 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
  6. 6. Pulsar drawbacks ● Immature ● No official .NET client
  7. 7. Challenge accepted ● 3 months ● 14 -> 2 members ● 1.5x faster than Java client ● 25x faster than RabbitMQ ● Another .NET client appeared
  8. 8. Let’s start!
  9. 9. Null-safety
  10. 10. Null-safety
  11. 11. Null-safety
  12. 12. Null-safety ● Code is Null-safe by default ● Exceptions are o Using Unsafe o Interoperability with C#
  13. 13. Immutability Code is immutable by default: No need to worry if message will be mutated
  14. 14. Builder
  15. 15. Immutable builder
  16. 16. Builder problems ● Mutability ● Boilerplate More on the topic: https://blog.ploeh.dk/2017/08/14/from-test-data-builders-to-the-identity-functor/
  17. 17. Builder
  18. 18. Identifiers
  19. 19. Identifiers https://andrewlock.net/using- strongly-typed-entity-ids-to- avoid-primitive-obsession-part-1/
  20. 20. Identifiers https://fsharpforfunandprofit.com/posts/designing-with-types-single-case-dus/
  21. 21. Identifiers with zero overhead
  22. 22. Ordering
  23. 23. Ordering Best code is no code.
  24. 24. 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
  25. 25. Problem: implement connection state
  26. 26. Problem: implement connection state
  27. 27. Problem: implement connection state
  28. 28. Locks
  29. 29. MailboxProcessor (Actor) Queue Loop Thread1 Thread2
  30. 30. MailboxProcessor (Actor) with async Queue Thread1 Thread2 ThreadPool Loop Channel
  31. 31. MailboxProcessor (Actor) with async
  32. 32. Problem: how to unit test?
  33. 33. Problem: how to unit test?
  34. 34. 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
  35. 35. Problem: how to unit test?
  36. 36. One object implementation
  37. 37. One object implementation
  38. 38. Conclusion ● No boilerplate ● No nulls ● No locks ● Concise and safe code https://fsharpforfunandprofit.com/posts/fsharp-is-the-best-enterprise-language/
  39. 39. Thank you! https://t.me/fsharp_chat https://t.me/pro_pulsar @Lanayx https://www.slideshare.net/Odin_cool/fsharp-goodness- for-everyday-work

×