Skip to content

Refactor: Migrate from Protocols to Behaviours for Transport Layer#85

Merged
joaop21 merged 20 commits intomainfrom
js/move-away-from-protocols
Aug 25, 2025
Merged

Refactor: Migrate from Protocols to Behaviours for Transport Layer#85
joaop21 merged 20 commits intomainfrom
js/move-away-from-protocols

Conversation

@joaop21
Copy link
Owner

@joaop21 joaop21 commented Aug 21, 2025

Why:

  1. Better Architecture for Service Contracts
  • Protocols are designed for data polymorphism and work best with structs
  • Behaviours are designed for service contracts and work best with stateful processes
  • Transports are stateful services that manage connections, not data structures
  1. Improved Performance
  • Protocols: Runtime dispatch with potential performance overhead
  • Behaviours: Direct function calls with compile-time optimization
  • Transport calls happen frequently in RPC systems, so performance matters
  1. Better Compile-Time Guarantees
  • Protocols: Interface compliance checked at runtime
  • Behaviours: Interface compliance enforced at compile time with @callback specs
  • Dialyzer can catch more issues, better IDE support
  1. Cleaner Dependency Management
  • Before: Transports had hidden dependencies on other modules
  • After: Explicit dependency injection of supervisor and registry via init_transport/2
  • No more cross-module coupling or hidden dependencies
  1. More Idiomatic Elixir/OTP Code
  • Behaviours align with OTP philosophy of explicit, well-defined service contracts
  • Better integration with supervision trees and process management
  • More familiar to Elixir developers working with OTP applications

@joaop21 joaop21 self-assigned this Aug 21, 2025
@joaop21 joaop21 merged commit f21fbe8 into main Aug 25, 2025
2 checks passed
@joaop21 joaop21 deleted the js/move-away-from-protocols branch August 25, 2025 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant