Making Market-Viewr More Robust with Caching and Retries

Hey everyone,

I've been keeping an eye on my server logs recently and noticed something I hate to see: the gunicorn worker for my Market-Viewr app was periodically dying and being restarted. The application was unstable under load, and it was time to investigate why.

It works so much faster!

After digging into the logs and doing some performance profiling, the culprit became clear. The application was making frequent, expensive API calls to fetch token richlists from Hive-Engine, especially when a user requested a CSV export. I realized the CSV export was making a separate, fresh pull of the entire richlist, even if the web page had just loaded it. This was inefficient and, for very large richlists, was causing the worker to time out or run out of resources.

To fix this and make the whole application more stable and performant, I've implemented two key backend improvements: caching and retry logic.

1. Smart Caching with a Fallback

The biggest improvement was adding a caching layer. In simple terms, caching stores the result of an expensive operation (like an API call) for a set period. If another request for the same data comes in during that period, the app serves the stored result instead of hitting the API again. This is massively more efficient.

I used the flask-caching library and set it up with a clever fallback system:

  • It first tries to connect to a Redis server, which is a fast, in-memory database perfect for caching.
  • If Redis is unavailable for any reason, it automatically falls back to a SimpleCache that just stores the data in the application's memory.

This ensures the app still benefits from caching even if the Redis service isn't running. I've applied different cache timeouts to different pages – for example, the homepage with the list of all tokens is cached for longer, while a specific token's market page has a shorter cache time to keep the data fresher.

2. Resilient API Calls with Retry Logic

The second issue is that sometimes API nodes can have a temporary blip or a network connection can fail. To make the app more resilient to these transient errors, I've configured the requests library to automatically retry failed requests.

If a connection to the Hive-Engine API fails, the app will now automatically try again a few times with a short delay between attempts. This means a temporary network hiccup is much less likely to result in an error page for the user.

The Result: A Faster, More Stable App

These backend changes should result in a noticeably better experience for you:

  • Faster Load Times: Many pages will now load almost instantly from the cache.
  • Increased Reliability: The site should be much more stable and less prone to errors or timeouts, especially when viewing tokens with large richlists.

While I was in there, I also made a small quality-of-life tweak to sort the richlist by the total holdings (staked + balance) by default, which gives a more accurate picture of a user's position.

These kinds of infrastructure improvements aren't as flashy as a new feature, but they are crucial for a good user experience. I hope you find the updated Market-Viewr to be a smoother and more reliable tool!

As always,
Michael Garcia a.k.a. TheCrazyGM

0.26571068 BEE
7 comments

I just tried Market-Viewr out again, and it's looking and working great! Congratulations on the fixes and refinements! 😁 🙏 💚 ✨ 🤙

0.00382023 BEE

I really like Market-Viewr!
I utilize it mainly to view token peice history over a longer peiod in time which isn't available on hive-engine / tribaldex.

Great app!

0.00379186 BEE

Is your site available to the public? Can I get the URL?

0.00347848 BEE

Absolutely, the main site is https://TheCrazyGM.com

The one I'm talking about today is: https://market.thecrazygm.com

0.00235736 BEE

Thanks.

0.00114652 BEE

While I was in there, I also made a small quality-of-life tweak to sort the richlist by the total holdings (staked + balance) by default, which gives a more accurate picture of a user's position.

@herman-german Thanks for pointing this out, should have fixed your issue as well.

0.00244452 BEE

Looking great now. Thanks for adding these fix 💪

0.00367691 BEE

Little by little we shall take over the world blockexplorer!

!PAKX
!PIMP
!PIZZA

0.00118659 BEE

View or trade PAKX tokens.

@ecoinstant, PAKX has voted the post by @thecrazygm. (2/2 calls)



Use !PAKX command if you hold enough balance to call for a @pakx vote on worthy posts! More details available on PAKX Blog.

0.00000000 BEE

PIZZA!

$PIZZA slices delivered:
@ecoinstant(2/20) tipped @thecrazygm

Come get MOONed!

0.00000000 BEE

Congratulations @thecrazygm! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You have been a buzzy bee and published a post every day of the week.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

0.00000000 BEE