<?xml version="1.0"?>
<ownershipDocument>

    <schemaVersion>X0508</schemaVersion>

    <documentType>4</documentType>

    <periodOfReport>2024-05-16</periodOfReport>

    <issuer>
        <issuerCik>0001092699</issuerCik>
        <issuerName>SPS COMMERCE INC</issuerName>
        <issuerTradingSymbol>SPSC</issuerTradingSymbol>
    </issuer>

    <reportingOwner>
        <reportingOwnerId>
            <rptOwnerCik>0001205069</rptOwnerCik>
            <rptOwnerName>WEHRWEIN SVEN</rptOwnerName>
        </reportingOwnerId>
        <reportingOwnerAddress>
            <rptOwnerStreet1>333 SOUTH SEVENTH STREET</rptOwnerStreet1>
            <rptOwnerStreet2>SUITE 1000</rptOwnerStreet2>
            <rptOwnerCity>MINNEAPOLIS</rptOwnerCity>
            <rptOwnerState>MN</rptOwnerState>
            <rptOwnerZipCode>55402</rptOwnerZipCode>
            <rptOwnerStateDescription></rptOwnerStateDescription>
        </reportingOwnerAddress>
        <reportingOwnerRelationship>
            <isDirector>1</isDirector>
        </reportingOwnerRelationship>
    </reportingOwner>

    <aff10b5One>0</aff10b5One>

    <nonDerivativeTable>
        <nonDerivativeTransaction>
            <securityTitle>
                <value>Common Stock</value>
            </securityTitle>
            <transactionDate>
                <value>2024-05-16</value>
            </transactionDate>
            <transactionCoding>
                <transactionFormType>4</transactionFormType>
                <transactionCode>A</transactionCode>
                <equitySwapInvolved>0</equitySwapInvolved>
            </transactionCoding>
            <transactionAmounts>
                <transactionShares>
                    <value>465</value>
                    <footnoteId id="F1"/>
                </transactionShares>
                <transactionPricePerShare>
                    <value>0</value>
                </transactionPricePerShare>
                <transactionAcquiredDisposedCode>
                    <value>A</value>
                </transactionAcquiredDisposedCode>
            </transactionAmounts>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>16212</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </nonDerivativeTransaction>
    </nonDerivativeTable>

    <derivativeTable>
        <derivativeTransaction>
            <securityTitle>
                <value>Stock Option (right to buy)</value>
            </securityTitle>
            <conversionOrExercisePrice>
                <value>80.31</value>
            </conversionOrExercisePrice>
            <transactionDate>
                <value>2024-05-16</value>
            </transactionDate>
            <transactionCoding>
                <transactionFormType>4</transactionFormType>
                <transactionCode>A</transactionCode>
                <equitySwapInvolved>0</equitySwapInvolved>
            </transactionCoding>
            <transactionAmounts>
                <transactionShares>
                    <value>1136</value>
                </transactionShares>
                <transactionPricePerShare>
                    <value>0</value>
                </transactionPricePerShare>
                <transactionAcquiredDisposedCode>
                    <value>A</value>
                </transactionAcquiredDisposedCode>
            </transactionAmounts>
            <exerciseDate>
                <footnoteId id="F2"/>
            </exerciseDate>
            <expirationDate>
                <value>2031-05-16</value>
            </expirationDate>
            <underlyingSecurity>
                <underlyingSecurityTitle>
                    <value>Common Stock</value>
                </underlyingSecurityTitle>
                <underlyingSecurityShares>
                    <value>1136</value>
                </underlyingSecurityShares>
            </underlyingSecurity>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>1136</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </derivativeTransaction>
    </derivativeTable>

    <footnotes>
        <footnote id="F1">The deferred stock units will vest in four equal installments on the last day of each fiscal quarter with the first vesting occurring on June 30, 2024, provided the reporting person remains a member of the board as of the vesting date. The deferred stock units must be retained until completion of the reporting person's service on the board, and upon completion of such service, convert into an equal number of shares of our common stock. The reporting person may defer receipt of the shares for up to ten years after completion of service.</footnote>
        <footnote id="F2">This option shall vest in four equal installments on the last day of each fiscal quarter with the first vesting occurring on June 30, 2024, provided the reporting person remains a member of the board as of the vesting date.</footnote>
    </footnotes>

    <ownerSignature>
        <signatureName>/s/ Jonathan R. Zimmerman, Attorney-in-Fact for Sven Wehrwein</signatureName>
        <signatureDate>2024-05-20</signatureDate>
    </ownerSignature>
</ownershipDocument>
