<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Yefym Dmukh</title>
    <description>The latest articles on DEV Community by Yefym Dmukh (@yefymdmukh_pb).</description>
    <link>https://dev.to/yefymdmukh_pb</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4174046%2F4fd8044a-21f9-42cb-8f23-c1f88e34c79b.jpg</url>
      <title>DEV Community: Yefym Dmukh</title>
      <link>https://dev.to/yefymdmukh_pb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yefymdmukh_pb"/>
    <language>en</language>
    <item>
      <title>Matching cycles, not pairs: the graph problem behind a B2B matching network</title>
      <dc:creator>Yefym Dmukh</dc:creator>
      <pubDate>Fri, 09 Oct 2026 18:37:05 +0000</pubDate>
      <link>https://dev.to/yefymdmukh_pb/matching-cycles-not-pairs-the-graph-problem-behind-a-b2b-matching-network-1e9b</link>
      <guid>https://dev.to/yefymdmukh_pb/matching-cycles-not-pairs-the-graph-problem-behind-a-b2b-matching-network-1e9b</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fproductbay.io%2Fopengraph-image%3F3ea63cf0fabd3ae2" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fproductbay.io%2Fopengraph-image%3F3ea63cf0fabd3ae2" alt="ProductBay.io — verified B2B matching network" width="1200" height="630"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am building &lt;a href="https://productbay.io" rel="noopener noreferrer"&gt;ProductBay (productbay.io)&lt;/a&gt;, a verified B2B matching network where companies buy each other's software and services, so software spend brings paying customers back. Under the business idea sits a nice little graph problem, and I want to walk through it because the obvious approach (match pairs) mostly does not work.&lt;/p&gt;

&lt;h2&gt;
  
  
  The naive model: pairs
&lt;/h2&gt;

&lt;p&gt;Every company in the network publishes two lists: what it sells and what it needs. The naive idea is to look for pairs: company A needs what B sells, and B needs what A sells. Both buy, both get a customer.&lt;/p&gt;

&lt;p&gt;In practice pairs are rare. A company selling a CRM needs HR software. The HR vendor needs a marketing tool. The marketing tool needs a CRM. Nobody forms a pair, but the three of them form a perfect loop.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjjjorea0n5j86xcx4sjl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjjjorea0n5j86xcx4sjl.png" alt="Without a network money goes out; with a network a customer comes back" width="800" height="518"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The better model: a directed graph and its cycles
&lt;/h2&gt;

&lt;p&gt;Model each company as a node. Draw an edge &lt;code&gt;A -&amp;gt; B&lt;/code&gt; when A needs what B sells (and B passes A's fit criteria). A "match" is now a directed cycle: everybody in the cycle buys from the next company and sells to the previous one, so every participant gets exactly one supplier and one customer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// needs: Map&amp;lt;companyId, Set&amp;lt;companyId&amp;gt;&amp;gt;  (A -&amp;gt; suppliers A would buy from)&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;shortCycles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;needs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;maxLen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;seen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;dfs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;needs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="p"&gt;[])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;([...&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
      &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;maxLen&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;dfs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="nx"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;})(&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;out&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Short cycles matter. A cycle of two or three companies is easy to explain and easy to accept. A cycle of eight companies is fragile: one "no" breaks it. So we cap the length and score cycles by fit, not by how clever they are.&lt;/p&gt;

&lt;h2&gt;
  
  
  Constraints that shape the algorithm
&lt;/h2&gt;

&lt;p&gt;The interesting part is not finding cycles, it is the rules around them:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Fit first.&lt;/strong&gt; An edge only exists if the buyer would buy that product anyway. Reciprocity never creates an edge on its own; it only ranks between edges that already make sense.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Full price, real orders.&lt;/strong&gt; Every edge is a normal order at the seller's published price. No netting, no credits. That keeps the graph honest: nobody can "pay" with favours.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;All or nothing.&lt;/strong&gt; A cycle only becomes real when every company in it accepts. Until then, nothing is charged. Each company has a limited window (24 hours) to accept; if it declines, the request goes to the next best candidate that fits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Linked cancellation.&lt;/strong&gt; If one company in the cycle cancels its order, the other orders in that match are cancelled too, so nobody keeps paying a supplier after their own customer has left.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Trial before payment.&lt;/strong&gt; Every match starts with a 7-day free trial on both sides. Payment starts only when the trial ends.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyyav1r6r51ywtdamoigi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyyav1r6r51ywtdamoigi.png" alt="From software spend to paying customers in 3 steps" width="800" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Trust is a graph property too
&lt;/h2&gt;

&lt;p&gt;A cycle is only as good as its weakest node. That is why verification happens before a company gets any edges at all: business check (KYB), founder identity, an active payment account, a live product, and a hands-on test by our team. Reputation (completed orders, renewals, reviews from verified buyers) then becomes an edge weight.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I think this is worth building
&lt;/h2&gt;

&lt;p&gt;Most small B2B companies spend a large part of their budget on tools from vendors that will never buy anything from them, and then pay again to find customers. A network that turns some of that spend into customers builds something like a startup cluster: a startup ecosystem where startups buying from startups is the normal case, not a lucky coincidence.&lt;/p&gt;

&lt;p&gt;ProductBay.io launches in Q4 2026. If you run a B2B product and want to see which of your future suppliers need what you sell, the waitlist is open at &lt;a href="https://productbay.io" rel="noopener noreferrer"&gt;productbay.io&lt;/a&gt;. And if you have solved a similar cycle-matching problem (kidney exchange is the classic reference), I would love to hear how you handled fragile long cycles.&lt;/p&gt;

</description>
      <category>startup</category>
      <category>saas</category>
      <category>algorithms</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
