Implement logic in Liquid that retrieves a list of the best-selling products

I have a task to do:
Implement logic in Liquid that retrieves a list of the best-selling products from the same category as the viewed product. Consider using product tags or collection types for filtering.

I have no idea how to go about it and filter through the best-selling products using liquid in the product page theme file?

Bump, is it even possible guys? I did it using our analytic database and meta fields where I sent the value of orders from the last month.