2. PRESENTED BY
1 Introduction to Microservices with Hydra + Redis
Pros/cons of a microservice architecture, and how Hydra + Redis ease microservice development.
2 Making Microservices with Hydra
A quick guide to building microservices in NodeJS with the Hydra and Hydra-Express libraries.
3 Plugins, Docker, Hydra 2.0
Extending Hydra with the plugin system, using Hydra with Docker, and previewing Hydra 2.0.
Agenda:
3. PRESENTED BY
Microservices provide benefits but come with costs.
• Pros
– Strong Module Boundaries
– Independent Deployments
– Technological Diversity
• Cons
– Distribution
– Eventual Consistency
– Operational Complexity
• Further reading
– https://martinfowler.com/articles/microservice-trade-offs.html
1a. Introduction: Microservices?
4. PRESENTED BY
Hydra enables rapid development of microservices with a minimal learning curve.
• Hydra provides core microservice functionality
– service presence and health monitoring
– service discovery and inter-service requests
– routing and load balancing
• Hydra has a small API and minimal dependencies.
– Hydra could be implemented in other languages.
• Just need to follow the same Redis usage conventions
1b. Introduction: Why build Microservices with Hydra?
5. PRESENTED BY
Hydra uses Redis to power all core features.
• Health/presence
– Strings, Expiration, Scan/Match
• Service Discovery
– Per-service information in hash hydra:service:nodes
• Routes
– Per-service routes in set hydra:service:<name>:service:routes
• e.g. [post]/v1/service/foo or [get]/v1/service/bar
• Inter-service Messaging
– Pub/Sub
• Per-instance channel: hydra:service:mc:<name>:<id>
• Service-wide channel: hydra:service:mc:<name>
1c. Introduction: How does Hydra use Redis?
6. PRESENTED BY
What’s available in the Hydra NPM ecosystem?
• hydra
– Core microservice features
• hydra-express
– Leverage ExpressJS for HTTP APIs and web apps
• hydra-router
– service-aware router via HTTP and WebSockets
• hydra-cli
– eases common tasks like checking health logs and managing service configurations
• hydra-plugins
– e.g. auth, logging, RPC
2a. Making Microservices with Hydra: NPM Ecosystem
7. PRESENTED BY
Overview of Hydra’s core functions.
• init
– Loads config.json and connects to Redis, puts Hydra in “Consumer mode.”
• registerService
– Registers this instance as a service, puts Hydra in “Service mode.”
– Hydra will now update health and presence in Redis.
• registerRoutes
– Register API endpoints for this service.
• sendMessage
– Send routable messages to services (broadcast, service-wide, or by instance ID)
• makeAPIRequest
– Make API requests to registered routes
2b. Making Microservices with Hydra: Core API
8. PRESENTED BY
Easily re-use features via plugins.
• Plugins can target hydra core
– hydra-plugin-<name>
• or hydra-express
– hydra-express-plugin-<name>
Current plugins include…
• JWT auth
– hydra-express-plugin-jwt-auth
• Logging
– fwsp-logger
3a. Making Microservices with Hydra: Plugins
9. PRESENTED BY
• fwsp-docker-scripts
– Adding this to package.json scripts will add “docker build” and “docker push”
– Automatically generates a simple Dockerfile
• Redis configuration
– config.json can be packaged in the image or pulled from Redis
– HYDRA_REDIS_URL and HYDRA_SERVICE environment variables
– hydra-cli cfg push/pull
• Health checks
– /v1/<service>/health route should return hydra.getHealth()
3b. Docker and Hydra