Coding Blocks

Joe goes full shock jock, but only for a moment. Allen loses the "Most Tips In A Single Episode: 2021" award, and Michael didn't get the the invite notification in this week's episode.

The full show notes for this episode are available at https://www.codingblocks.net/episode168.

Sponsors

  • Datadog – Sign up today for a free 14 day trial and get a free Datadog t-shirt after creating your first dashboard.
  • Shortcut - Project management has never been easier. Check out how Shortcut (formerly known as Clubhouse) is project management without all the management.

Survey Says

Well...no survey this week, but this is where it would be!

News

Designing Data Intensive Applications This book has a whole chapter on transactions in distributed systems

  • Thank you to everyone that left a review!
    • "Podchaser: alexi*********, Nicholas G Larsen, Kubernutties,
    • iTunes: Kidboyadde, Metalgeeksteve, cametumbling, jstef16, Fr1ek
    • Audible: Anonymous (we are like your mother - go clean your room and learn Docker)

  • Atlanta Code Camp is right around the corner on October 9th. Stop by the CB booth and say hi! (AtlantaCodeCamp.com)

Maintaining data consistency

  • Each service should have its own data store
  • What about transactions? microservices.io suggests the saga pattern (website)
  • A sequence of local transactions must occur
    • Order service saves to its data store, then sends a message that it is done
    • Customer service attempts to save to its data store…if it succeeds, the transaction is done. If it fails, it sends a message stating so, and then the Order service would need to run another update to undo the previous action
  • Sound complicated? It is…a bit, you can't rely on a standard 2 Phase Commit at the database level to ensure an atomic transaction
  • Ways to achieve this - choreography or orchestration

Choreography Saga

- The Order Service receives the POST /orders request and creates an Order in a PENDING state
- It then emits an Order Created event
- The Customer Service’s event handler attempts to reserve credit
- It then emits an event indicating the outcome
- The OrderService’s event handler either approves or rejects the Order

  • Each service's local transaction sends a domain event that triggers another service's local transaction
  • To sum things up, each service knows where to listen for work it should do, and it knows where to publishes the results of it's work. It's up to the designers of the system to set things up such that the right things happened
  • What's good about this approach?

"The code I wrote sux. The code I'm writing is cool. The code I'm going to write rocks!"

Thanks for the paraphrase Mike!

Orchestration Saga

- The Order Service receives the POST /orders request and creates the Create Order saga orchestrator
- The saga orchestrator creates an Order in the PENDING state
- It then sends a Reserve Credit command to the Customer Service
- The Customer Service attempts to reserve credit
- It then sends back a reply message indicating the outcome
- The saga orchestrator either approves or rejects the Order

  • There is an orchestrator object that tells each service what transaction to run
  • The difference between Orchestration and Choreography is that the orchestration approach has a "brain" - an object that centralizes the logic and can make more advanced changes
  • These patterns allow you to maintain data consistency across multiple services
  • The programming is quite a bit more complicated - you have to write rollback / undo transactions - can't rely on ACID types of transactions we've come to rely on in databases
  • Other issues to understand
    • The service must update the local transaction AND publish the message / event
    • The client that initiates the saga (asynchronously) needs to be able to determine the outcome
      • The service sends back a response when the saga completes
      • The service sends back a response when the order id is created and then polls for the status of the overall saga
      • The service sends back a response when the order id is created and then submits an event via a webhook or similar when the saga completes
  • When would you use Orchestration vs Choreography for transactions across Microservices?
  • Friend of the show @swyx works for Temporal, a company that does microservice orchestration as a service, https://temporal.io/

Tips for writing Great Microservices

Fantastic article on how to keep microservices loosely coupled
https://www.capitalone.com/tech/software-engineering/how-to-avoid-loose-coupled-microservices/

  • Mentions using separate data storage / dbs per service
    • Can't hide implementation from other services if they can see what's happening behind the scenes - leads to tight coupling
  • Share as little code as possible
    • Tempting to share things like customer objects, but doing so tightly couples the various microservices
      • Better to nearly duplicate those objects in a NON-shared way - that way the services can change independently
  • Avoid synchronous communication where possible
    • This means relying on message brokers, polling, callbacks, etc
  • Don't use shared test environments / appliances
    • May not sound right, but sharing a service may lead to problems - like multiple services using the same test service could introduce performance problems
  • Share as little domain data as possible - ie. important pieces of information shouldn't be passed around various services in domain objects. Only the bits of information necessary should be shared with each service - ie an order number or a customer number. Just enough to let the next microservice be able to do its job

Resources

Tip of the Week

  • Podman is an open-source containerization tool from Red Hat that provides a drop in replacement for Docker (they even recommend aliasing it!). The major difference is in how it works underneath, spawning process directly rather than relying on resident daemons. Additionally, podman was designed in a post Kubernetes world, and it has some additional tooling that makes it easier to transition to Kubernetes- like being able to spawn pods and generate Kubernetes yaml files. Website
    • Check out this episode from Google's Kubernetes podcast all about it: Podcast
  • Unity is the most popular game engine and they have a ton of resources in their Learning Center. Including one that is focused on writing code. It walks you through writing 5 microgames with hands on exercises where you fix projects and ultimately design and write your own simple game. Also it's free! https://learn.unity.com/course/create-with-code
    • Bonus: Make sure you subscribe to Jason Weimann's YouTube channel if you are interested in making games. Brilliant coder and communicator has a wide variety of videos: YouTube
  • Educative.io has been a sponsor of the show before and we really like their approach to hands on teaching so Joe took a look to see if they had any resources on C++ since he was interested in possibly pursuing competitive programming. Not only do they have C++ courses, but they actually have a course specifically for Competitive Programming in C++. Great for devs who already know a programming language and are wanting to transition without having to start at step 1. Educative Course
  • The most recent Coding Blocks Mailing List contest asked for "Summer Song" recommendations, we compiled them into a Spotify Summer Playlist. These are songs that remind you of summer, and don't worry we deduped the list so there is only one song from Rick Astley on there. Spotify
  • Finally, one special recommendation for Coding Music. It's niche, for sure, but if you like coding to instrumental rock/hard-rock then you have to check out a 2018 album from a band called Night Verses. It's like Russian Circles had a baby with the Mercury Program. If you are familiar with either of those bands, or just want something different then make sure to check it out. Spotify

Direct download: coding-blocks-episode-168.mp3
Category:Software Development -- posted at: 8:01pm EDT

Some things just require discussion, such as Docker’s new licensing, while Joe is full of it, Allen *WILL* fault them, and Michael goes on the record.

The full show notes for this episode are available at https://www.codingblocks.net/episode167.

Sponsors

  • Datadog – Sign up today for a free 14 day trial and get a free Datadog t-shirt after creating your first dashboard.
  • Shortcut – Project management has never been easier. Check out how Shortcut (formerly known as Clubhouse) is project management without all the management.

Survey Says

How do you get prefer to get on the network?

Take the survey at: https://www.codingblocks.net/episode167.

News

  • Thank you to everyone that left a review!
    • iTunes: Badri Ravi
    • Audible: Dysrhythmic, Brent
  • Atlanta Code Camp is right around the corner on October 9th. Stop by the CB booth and say hi! (AtlantaCodeCamp.com)

Docker Announcement

Docker recently announced big changes to the licensing terms and pricing for their product subscriptions. These changes would mean some companies having to pay a lot more to continue using Docker like they do today. So…what will will happen? Will Docker start raking in the dough or will companies abandon Docker?

Resources
  • Docker is Updating and Extending Our Product Subscriptions (Docker)
  • Minkube documentation (Thanks MadVikingGod! From the Tips n’ Tools channel in Slack.)
  • Open Container Initiative, an open governance structure for the purpose of creating open industry standards around container formats and runtimes. (opencontainers.org)
  • Podman, a daemonless container engine for developing, managing, and running OCI containers. (podman.io)
  • Getting Started with K9s (YouTube)

How valuable is education?

How do you decide when it’s time to go back to school or get a certification? What are the determining factors for making those decisions?

Full-Stack Road Map

What’s on your roadmap? We found a full-stack roadmap on dev.to and it’s got some interesting differences from other roadmaps we’ve seen or the roadmaps we’ve made. What are those differences?

Resources
  • Full Stack Developer’s Roadmap (dev.to)

Bonus Tip: You can find the top dev.to articles for certain time periods like: https://dev.to/top/year. Works for week, month, and day, too.

Where does your business logic go?

Business logic should be in a service, not in a model … or should it? What’s the right way to do this? Is there a right way?

Resources

Are the M1/M1X chips a good idea for devs?

Last year’s MacBook Pros introduced new M1 processors based on a RISC architecture. Now Apple is rolling out the rest of the line. What does this mean for devs? Is there a chance you will regret purchasing one of these laptops?

Resources
  • Apple Silicon M1: A Developer’s Perspective (steipete.com)

Tip of the Week

  • Hit . (i.e. the period key) in GitHub to bring up an online VS Code editor while you are logged in. Thanks Morten Olsrud! (blog.yogeshchavan.dev)
    • Shoutout to Coder, cloud-powered development environments that feel local. (coder.com)
  • The podcast that puts together the the “perfect album” for the topic du jour: The Perfect Album Side Podcast (iTunesSpotifyGoogle Podcasts)
    • Bon Jovi – Livin’ On A Prayer / Wanted Dead Or Alive (Los Angeles 1989) (YouTube)
  • Docker’s system prune command now includes a filter option to easily get rid of older docker resources. (docs.docker.com)
    • Example: docker system prune --filter="until=72h"
  • The GitHub CLI makes it easy to create PR by autofilling information, as well as pushing your branch to origin:
  • Apache jclouds is an open-source multi-cloud toolkit that abstracts the details of your cloud provider away so you can focus on your code and still support multiple providers. (jclouds.apache.org)
Direct download: coding-blocks-episode-167.mp3
Category:Software Development -- posted at: 9:44pm EDT

1